Giter Club home page Giter Club logo

finder's Introduction

Nette Finder: Files Searching

Nette Finder makes browsing the directory structure really easy.

Documentation can be found on the website.

The library has been moved to the nette/utils

finder's People

Contributors

dg avatar fprochazka avatar jantvrdik avatar juniwalk avatar ls05 avatar majkl578 avatar martkcz avatar michal-mikolas avatar vrana avatar vrtak-cz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finder's Issues

Maximum execution time of 90 seconds exceeded

Version: 2.5.2

Bug Description

Hi, I am using Nette framework.
I get the following exception several times an hour when users are browsing my website (on different pages):
Fatal Error: Maximum execution time of 90 seconds exceeded in /vendor/nette/finder/src/Utils/Finder.php:234

I have slightly modified the Finder.php to add some additional logging:

	private function buildIterator(string $path): \Iterator
	{
		$iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS);

		if ($this->exclude) {
			$iterator = new \RecursiveCallbackFilterIterator($iterator, function ($foo, $bar, RecursiveDirectoryIterator $file): bool {
				if (!$file->isDot() && !$file->isFile()) {
					foreach ($this->exclude as $filter) {
						if (!$filter($file)) {
							return false;
						}
					}
				}
				return true;
			});
		}

		if ($this->maxDepth !== 0) {
			$iterator = new RecursiveIteratorIterator($iterator, $this->order);
			$iterator->setMaxDepth($this->maxDepth);
		}

		Debugger::enable(Debugger::DETECT, __DIR__ . '/../../../../../log', '[email protected]');

		Debugger::log("path: " . $path, Debugger::INFO);

		$iterator = new \CallbackFilterIterator($iterator, function ($foo, $bar, \Iterator $file): bool {

			Debugger::log("file: " . get_class($file) . " at iteration 0", Debugger::INFO);
			$i = 0;

			while ($file instanceof \OuterIterator) {
				$file = $file->getInnerIterator();
				Debugger::log("file: " . get_class($file) . " at iteration " . ++$i, Debugger::INFO);
			}

			foreach ($this->groups as $filters) {
				foreach ($filters as $filter) {
					if (!$filter($file)) {
						continue 2;
					}
				}
				return true;
			}
			return false;
		});

		return $iterator;
	}

Here is the output:

[2020-12-26 00-06-08] path: /app/../temp/cache @ https://@@@.com/main/forums?backUrl=fld1n
[2020-12-26 00-06-08] file: RecursiveIteratorIterator at iteration 0 @ https://@@@.com/main/forums?backUrl=fld1n
[2020-12-26 00-06-08] file: RecursiveDirectoryIterator at iteration 1 @ https://@@@.com/main/forums?backUrl=fld1n
[2020-12-26 00-06-08] file: RecursiveIteratorIterator at iteration 0 @ https://@@@.com/main/forums?backUrl=fld1n
[2020-12-26 00-06-08] file: RecursiveDirectoryIterator at iteration 1 @ https://@@@.com/main/forums?backUrl=fld1n
[2020-12-26 00-06-08] file: RecursiveIteratorIterator at iteration 0 @ https://@@@.com/main/forums?backUrl=fld1n
[2020-12-26 00-06-08] file: RecursiveDirectoryIterator at iteration 1 @ https://@@@.com/main/forums?backUrl=fld1n
... Endless cycle until maximum execution time exceeded ...

Steps To Reproduce

I don't know the steps as I can't reproduce the problem myself, I only get notifications about the exception.

Expected Behavior

No error is expected.

Do not build the iterator each time

Hi again,

I've noticed that the iterator is created each time we iterate on the Finder (or I missed something in the way iterators work, which is really possible).

The getIterator method always call buildIterator which creates a new instance.

Could it be possible to not always create it and keep it cached to be re-used?

I understand that from between two iterations, the filesystem may have changed. But in some cases, we know it does not.

Use case example: I want to build a static website. I iterate over the files one first time, to gather data (categories, tags, authors, etc.). Then I iterate a second time to compile all files, using the data collected during the first pass. If the filesystem has changed, it's my responsibility. When I build the static website, I build it, I don't write its content.

This could be a new method (findFilesOnce for example) which would set an option to keep the iterator cached for latter use.

EDIT: I may provide a PR to add this feature.

Readme instructions don't install project

Just had a silly few mins trying to use this project and php complaining it couldn't find Finder class. Couldn't understand the code to see Finder either, so came here and got very confused why it was all different.

Eventually realised that the readme says composer require nette/utils where as you actually need composer require nette/finder to get this project.

Figured it was a typo I could PR, but then saw you've a single commit changing finder to utils in the instructions which looks more intentional: c93ddaf

Was this change intentional? Is there a way installing with /utils should work?

Allow to specify the file info class

Hi,

I'd love to be able to use the Finder and get a specific class rather than the default SplFileInfo class.

It could be specified with something like:

Finder::findFiles('*.md')->as(CustomFileInfo::class)->from('path/to/files');

The as() method would call setInfoClass method on the iterator.

If you're interested in this feature, I can provide a PR.

Throw exception if you haven't last call methods from() or in()

Motivation

Two times happen me, i forgot for this behavior, when you must call from() or in() like a last methods.

Describe problem

This is right and works fine. This example is in documentation.

Finder::findFiles('*.php')->date('>', '- 2 weeks')->from($dir);

But if you change call of methods, because both are support fluent.

Finder::findFiles('*.php')->from($dir)->date('>', '- 2 weeks');

The example could throw exception.

This is bad, because on first look, it is ok, nothing happend.
But it works bad. Every time i seach why does not work, because it rewrites internal reference.

Resolve problem

One instance of Finder is for one search. I think internal state can freeze after call in() or from() and throw exception if you call other methods exclude interface's methods.

Symbols in description item of composer.json cause issue in Gitlab

Dear developers,
we have an issue when integrating your nette/* packages. Our current version of Gitlab (GitLab Enterprise Edition 11.2.5-ee) and the MariaDB behind it seem to be unable to handle your symbols in the description items of your composer.json files. Thus we can not create merge requests anymore.

"description": "๐Ÿ” Nette Finder: find files and directories with an intuitive API.",

Do you think it is possible that you remove these symbols and provide new patch versions of all of your packages?

To be precise, we have these dependencies

  • ๐Ÿ…ฑ Nette Bootstrap
  • ๐Ÿ’Ž Nette Dependency Injection Container
  • ๐Ÿ” Nette Finder
  • ๐Ÿธ Nette NEON
  • ๐Ÿ˜ Nette PHP Generator
  • ๐Ÿ€ Nette RobotLoader
  • ๐Ÿ“ Nette Schema
  • ๐Ÿ›  Nette Utils

Thank you in advance!

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.