This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Finder
Lukas Kahwe Smith 34fc866b5a cosmetic tweaks
2011-11-03 21:26:29 +01:00
..
Comparator removed unused variables 2011-03-21 11:22:29 +01:00
Iterator fixed CS 2011-06-08 12:16:48 +02:00
composer.json [composer] add composer.json 2011-09-27 00:55:43 +02:00
Finder.php [Finder] added a convenience method Finder::create() 2011-06-14 14:18:24 +02:00
Glob.php [Phpdoc] Cleaning/fixing 2011-04-23 15:18:47 +00:00
LICENSE added LICENSE files for the subtree repositories 2011-02-22 18:58:15 +01:00
README.md cosmetic tweaks 2011-11-03 21:26:29 +01:00
SplFileInfo.php [Phpdoc] Cleaning/fixing 2011-04-23 15:18:47 +00:00

Finder Component

The Finder provides a very convenient and nice fluent interface to find files and directories on the filesystem:

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";
}

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

Unit tests:

https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/Finder