107765142e
* 2.8: fixed test [Request] Ignore invalid IP addresses sent by proxies [EventDispatcher] TraceableEventDispatcher resets listener priorities Throw for missing container extensions [TwigBridge] add missing unit tests (AppVariable) Able to load big xml files with DomCrawler fixed typo [Form] Fix constraints could be null if not set [Finder] Check PHP version before applying a workaround for a PHP bug fixed CS add defaultNull to version sort bundles in config:dump-reference command Fixer findings. Profiler CSS position conflicts with JS detection [Translation][Writer] avoid calling setBackup if the dumper is not an instance of FileDumper. [FrameworkBundle] Compute the kernel root hash only one time |
||
---|---|---|
.. | ||
Comparator | ||
Exception | ||
Iterator | ||
Tests | ||
.gitignore | ||
CHANGELOG.md | ||
composer.json | ||
Finder.php | ||
Glob.php | ||
LICENSE | ||
phpunit.xml.dist | ||
README.md | ||
SplFileInfo.php |
Finder Component
Finder finds files and directories via an intuitive fluent interface.
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$iterator = $finder
->files()
->name('*.php')
->depth(0)
->size('>= 1K')
->in(__DIR__);
foreach ($iterator as $file) {
print $file->getRealpath()."\n";
}
The iterator returns instances of Symfony\Component\Finder\SplFileInfo\SplFileInfo.
Besides the build-in methods inherited from \SplFileInfo (getPerms()
, getSize()
, ...),
you can also use getRelativePath()
and getRelativePathname()
. Read the
official documentation for more information.
But you can also use it to find files stored remotely like in this example where we are looking for files on Amazon S3:
$s3 = new \Zend_Service_Amazon_S3($key, $secret);
$s3->registerStreamWrapper("s3");
$finder = new Finder();
$finder->name('photos*')->size('< 100K')->date('since 1 hour ago');
foreach ($finder->in('s3://bucket-name') as $file) {
print $file->getFilename()."\n";
}
Resources
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/Finder/
$ composer install
$ phpunit