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: find files and directories with an intuitive API.
Home Page: https://doc.nette.org/finder
License: Other
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
Version: 2.5.2
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 ...
I don't know the steps as I can't reproduce the problem myself, I only get notifications about the exception.
No error is expected.
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.
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?
PHP 7.4 reports E_DEPRECATED: Cannot use "parent" when current class scope has no parent
at this line. I am not sure what is purpose of parent call here, but shouldn't it be $this->
?
https://travis-ci.org/contributte/di/jobs/554846041#L242-L262
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.
Two times happen me, i forgot for this behavior, when you must call from() or in() like a last methods.
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.
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.
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
Thank you in advance!
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.