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
2012-03-31 19:48:43 +01:00
..
Comparator [DoctrineBridge] fixed some CS 2011-12-13 10:22:12 +01:00
Iterator [Finder] Added sortBy options based on accessed, changed and modified times 2012-03-31 19:48:43 +01:00
Tests [Finder] Added sortBy options based on accessed, changed and modified times 2012-03-31 19:48:43 +01:00
composer.json Removed version field 2012-02-27 09:59:20 +01:00
Finder.php [Finder] Added sortBy options based on accessed, changed and modified times 2012-03-31 19:48:43 +01:00
Glob.php [Phpdoc] Cleaning/fixing 2011-04-23 15:18:47 +00:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
phpunit.xml.dist [PhpUnit] Fix the path to the boostrap files in the components 2012-03-30 13:49:28 +02:00
README.md moved component and bridge unit tests to the src/ directory 2012-03-29 08:37:22 +02:00
SplFileInfo.php [Phpdoc] Cleaning/fixing 2011-04-23 15:18:47 +00:00

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

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:

phpunit -c src/Symfony/Component/Finder/