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
Nicolas Grekas 8cf0613ead Merge branch '2.6' into 2.7
* 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
2015-04-18 17:11:06 +02:00
..
Adapter CS: Binary operators should be arounded by at least one space 2015-03-27 23:05:05 +01:00
Comparator CS: Binary operators should be arounded by at least one space 2015-03-27 23:05:05 +01:00
Exception Merge branch '2.2' 2013-04-22 06:30:07 +02:00
Expression Removed duplicated toRegex() code 2015-04-11 21:29:31 +02:00
Iterator Merge branch '2.3' into 2.5 2014-12-30 14:32:44 +01:00
Shell Merge branch '2.3' into 2.6 2015-03-30 17:54:10 +02:00
Tests Merge branch '2.6' into 2.7 2015-04-18 17:11:06 +02: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 Use PSR-4 everywhere instead of PSR-0 2015-04-11 23:38:32 +02:00
Finder.php Merge branch '2.3' into 2.6 2015-03-12 11:28:44 +01:00
Glob.php Removed duplicated toRegex() code 2015-04-11 21:29:31 +02:00
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
phpunit.xml.dist [2.3] require-dev PHPUnit bridge 2015-02-24 11:24:26 +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