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
2015-02-15 15:36:33 +01:00
..
Adapter Fixes various phpdoc and coding standards. 2015-01-02 09:58:20 +01:00
Comparator Fixes various phpdoc and coding standards. 2015-01-02 09:58:20 +01:00
Exception Merge branch '2.2' 2013-04-22 06:30:07 +02:00
Expression Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
Iterator use value of DIRECTORY_SEPARATOR to detect Windows 2014-12-30 12:17:23 +01:00
Shell [2.3] Remove possible call_user_func() 2014-11-21 10:26:02 +01:00
Tests use value of DIRECTORY_SEPARATOR to detect Windows 2014-12-30 12:17:23 +01:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md [Finder] updated CHANGELOG 2013-04-22 15:01:19 +02:00
composer.json updated the branch alias in composer files 2013-01-31 22:39:01 +01:00
Finder.php [Finder] Fixed typo in phpdoc comment 2015-02-15 15:36:33 +01:00
Glob.php Docblock fixes 2014-11-30 13:33:44 +00:00
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
phpunit.xml.dist [Tests] Silenced all deprecations in tests for 2.3 2014-12-18 20:00:19 +01:00
README.md renamed composer.phar to composer to be consistent with the Symfony docs 2015-02-08 08:41:14 +01:00
SplFileInfo.php [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01: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";
}

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