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
Fabien Potencier 77bfac719c Merge branch '2.4'
* 2.4:
  [Form][2.3] Fixes empty file-inputs getting treated as extra field.
  changed some PHPUnit assertions to more specific ones
  fixed Kernel::stripComments() normalizing new-lines
  added a BC comment
  Update FileLoader to fix issue #10339
  bumped Symfony version to 2.3.12
  updated VERSION for 2.3.11
  update CONTRIBUTORS for 2.3.11
  updated CHANGELOG for 2.3.11
  Throw exception when unable to normalize embedded object
  Fixed evaluation of short circuit operators
  Follow-up to #10312: Fixed minor performance related issues in Yaml\Inline.
  [2.4][HttpKernel] Fix issue #10209 When the profiler has `only_exception` option activated and a subrequest throw an exception, the parent profile cannot be found.
2014-03-03 13:53:01 +01:00
..
Adapter merged branch jfsimon/issue-6981 (PR #7518) 2013-04-22 15:00:38 +02:00
Comparator Fixed most of the docblocks/unused namespaces 2012-12-19 08:09:49 +01:00
Exception Merge branch '2.2' 2013-04-22 06:30:07 +02:00
Expression () is also a valid delimiter 2014-02-20 16:15:12 +01:00
Iterator feature #9360 [Finder] Fix finder date constraints and tests (ruian) 2013-12-27 22:51:59 +01:00
Shell Merge branch '2.3' into 2.4 2013-12-28 09:12:03 +01:00
Tests Merge branch '2.4' 2014-03-03 13:53:01 +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.5 2013-11-24 21:17:07 +01:00
Finder.php [Finder] Added GLOB_BRACE support in Finder::in() method 2014-01-01 15:41:52 +00:00
Glob.php fixed CS 2012-07-09 14:54:20 +02:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
README.md updated the composer install command to reflect changes in Composer 2013-09-18 09:27:26 +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";
}

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