|
1 | 1 | Finder Component
|
2 | 2 | ================
|
3 | 3 |
|
4 |
| -Finder finds files and directories via an intuitive fluent interface. |
5 |
| - |
6 |
| -```php |
7 |
| -use Symfony\Component\Finder\Finder; |
8 |
| - |
9 |
| -$finder = new Finder(); |
10 |
| - |
11 |
| -$iterator = $finder |
12 |
| - ->files() |
13 |
| - ->name('*.php') |
14 |
| - ->depth(0) |
15 |
| - ->size('>= 1K') |
16 |
| - ->in(__DIR__); |
17 |
| - |
18 |
| -foreach ($iterator as $file) { |
19 |
| - print $file->getRealpath()."\n"; |
20 |
| -} |
21 |
| -``` |
22 |
| - |
23 |
| -The iterator returns instances of [Symfony\Component\Finder\SplFileInfo\SplFileInfo][1]. |
24 |
| -Besides the build-in methods inherited from [\SplFileInfo][2] (`getPerms()`, `getSize()`, ...), |
25 |
| -you can also use `getRelativePath()` and `getRelativePathname()`. Read the |
26 |
| -[official documentation][3] for more information. |
27 |
| - |
28 |
| -But you can also use it to find files stored remotely like in this example where |
29 |
| -we are looking for files on Amazon S3: |
30 |
| - |
31 |
| -```php |
32 |
| -$s3 = new \Zend_Service_Amazon_S3($key, $secret); |
33 |
| -$s3->registerStreamWrapper("s3"); |
34 |
| - |
35 |
| -$finder = new Finder(); |
36 |
| -$finder->name('photos*')->size('< 100K')->date('since 1 hour ago'); |
37 |
| -foreach ($finder->in('s3://bucket-name') as $file) { |
38 |
| - print $file->getFilename()."\n"; |
39 |
| -} |
40 |
| -``` |
| 4 | +The Finder component finds files and directories via an intuitive fluent |
| 5 | +interface. |
41 | 6 |
|
42 | 7 | Resources
|
43 | 8 | ---------
|
44 | 9 |
|
45 |
| -You can run the unit tests with the following command: |
46 |
| - |
47 |
| - $ cd path/to/Symfony/Component/Finder/ |
48 |
| - $ composer install |
49 |
| - $ phpunit |
50 |
| - |
51 |
| -[1]: http://api.symfony.com/2.5/Symfony/Component/Finder/SplFileInfo.html |
52 |
| -[2]: http://php.net/splfileinfo |
53 |
| -[3]: https://symfony.com/doc/current/components/finder.html#usage |
| 10 | + * [Documentation](https://symfony.com/doc/current/components/finder.html) |
| 11 | + * [Contributing](https://symfony.com/doc/current/contributing/index.html) |
| 12 | + * [Report issues](https://github.com/symfony/symfony/issues) and |
| 13 | + [send Pull Requests](https://github.com/symfony/symfony/pulls) |
| 14 | + in the [main Symfony repository](https://github.com/symfony/symfony) |
0 commit comments