8cf0613ead
* 2.6: [Routing][DependencyInjection] Support .yaml extension in YAML loaders [DX] improve file loader error for router/other resources in bundle [FrameworkBundle] Initialize translator with the default locale. [FrameworkBundle] Fix Routing\DelegatingLoader resiliency to fatal errors [2.6][Translation] remove duplicate code for loading catalogue. [HttpKernel] Cleanup ExceptionListener CS fixes [DependencyInjection] Show better error when the Yaml component is not installed [2.3] SCA for Components - reference mismatches [Debug] Scream as LogLevel::DEBUG (but for fatal errors / uncaught exceptions) [2.3] Static Code Analysis for Components [WebProfilerBundle] Fix resiliency to exceptions thrown by the url generator [Translation] LoggingTranslator simplifications [Translation][fixed test] refresh cache when resources are no longer fresh. [FrameworkBundle] Fixed server:start --router relative path issue #14124 [FrameworkBundle] improve usage of Table helper [Validator] Added missing Simplified Chinese (zh_CN) translations [FrameworkBundle] Workaround php -S ignoring auto_prepend_file Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php src/Symfony/Component/Console/Helper/Table.php src/Symfony/Component/Translation/LoggingTranslator.php |
||
---|---|---|
.. | ||
Adapter | ||
Comparator | ||
Exception | ||
Expression | ||
Iterator | ||
Shell | ||
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