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
2014-11-10 19:00:54 +01:00
..
Adapter Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
Comparator fixed CS 2014-09-22 10:32:35 +02: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 Merge branch '2.3' into 2.5 2014-10-26 08:41:27 +01:00
Shell Merge branch '2.3' into 2.5 2014-10-26 08:41:27 +01:00
Tests Merge branch '2.3' into 2.5 2014-10-26 08:41:27 +01:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md [Finder] Included GLOB_BRACE support in the CHANGELOG. 2014-01-01 15:45:37 +00:00
composer.json updated version to 2.7 2014-11-10 19:00:54 +01:00
Finder.php Merge branch '2.3' into 2.5 2014-10-26 08:41:27 +01:00
Glob.php made phpdoc types consistent with those defined in Hack 2014-04-15 07:41:45 +02:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
phpunit.xml.dist removed defaults from PHPUnit configuration 2014-07-07 12:13:42 +02:00
README.md Merge branch 'pull/12053' into 2.3 2014-10-01 07:39:06 +02:00
SplFileInfo.php [Finder] Fix SplFileInfo::getContents isn't working with ssh2 protocol 2013-06-10 20:35:46 +02: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.phar install
$ phpunit