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 89e86197c1 minor #17480 Static code analysis (Koc)
This PR was merged into the 2.3 branch.

Discussion
----------

Static code analysis

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Things that done:
* fix case in method calls
* removed unused imports
* use shorter concat where it possible
* optimize some css
* removed duplicated array keys
* removed redurant return statements
* removed one-time variables
* do not pass arguments that not used in functions

Commits
-------

8db691a Static code analysis
2016-01-27 05:57:57 +01:00
..
Adapter Static code analysis 2016-01-25 19:00:36 +02: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 CS: Pre incrementation/decrementation should be used if possible 2015-04-07 19:54:22 +02:00
Iterator [Finder] Check PHP version before applying a workaround for a PHP bug 2016-01-25 08:54:54 +01:00
Shell [Finder] Command::addAtIndex() fails with Command instance argument 2015-07-08 07:54:32 +02:00
Tests minor #17134 [Finder] Check PHP version before applying a workaround for a PHP bug (alebo) 2016-01-25 08:55:01 +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 added the new Composer exclude-from-classmap option 2015-10-30 12:48:51 -07:00
Finder.php remove api tags from code 2015-09-28 19:11:22 +02:00
Glob.php Escape the delimiter in Glob::toRegex 2016-01-25 17:35:23 +01:00
LICENSE Update copyright year 2016-01-01 23:53:47 -03:00
phpunit.xml.dist Add missing exclusions from phpunit.xml.dist 2015-11-18 09:19:46 +01:00
README.md link to https://symfony.com where possible 2015-05-01 16:06:45 +02:00
SplFileInfo.php Improve the phpdoc of SplFileInfo methods 2016-01-19 13:10:23 +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