Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (40 sloc) 1.393 kb
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
1 Finder Component
2 ================
3
bc74d69 @fabpot tweaked the README files
fabpot authored
4 Finder finds files and directories via an intuitive fluent interface.
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
5
71d8f33 @lologhi [Doc] Use Markdown syntax highlighting
lologhi authored
6 ```php
7 use Symfony\Component\Finder\Finder;
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
8
71d8f33 @lologhi [Doc] Use Markdown syntax highlighting
lologhi authored
9 $finder = new Finder();
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
10
71d8f33 @lologhi [Doc] Use Markdown syntax highlighting
lologhi authored
11 $iterator = $finder
12 ->files()
13 ->name('*.php')
14 ->depth(0)
15 ->size('>= 1K')
16 ->in(__DIR__);
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
17
71d8f33 @lologhi [Doc] Use Markdown syntax highlighting
lologhi authored
18 foreach ($iterator as $file) {
19 print $file->getRealpath()."\n";
20 }
21 ```
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
22
df02aaf @fabpot [Finder] tweaked docs
fabpot authored
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.
a2521dc @ywarnier [Finder] Add info about possibilities offered by SplFileInfo
ywarnier authored
27
7485a20 @lsmith77 cosmetic tweaks
lsmith77 authored
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:
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
30
71d8f33 @lologhi [Doc] Use Markdown syntax highlighting
lologhi authored
31 ```php
32 $s3 = new \Zend_Service_Amazon_S3($key, $secret);
33 $s3->registerStreamWrapper("s3");
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
34
71d8f33 @lologhi [Doc] Use Markdown syntax highlighting
lologhi authored
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 ```
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
41
42 Resources
43 ---------
44
713ba1d @fabpot moved component and bridge unit tests to the src/ directory
fabpot authored
45 You can run the unit tests with the following command:
b88d67d @lsmith77 added basic README files for all components
lsmith77 authored
46
2610ebb @fabpot made usage of Composer autoloader for subtree-split unit tests
fabpot authored
47 $ cd path/to/Symfony/Component/Finder/
b17b334 @fabpot renamed composer.phar to composer to be consistent with the Symfony docs
fabpot authored
48 $ composer install
2610ebb @fabpot made usage of Composer autoloader for subtree-split unit tests
fabpot authored
49 $ phpunit
50
df02aaf @fabpot [Finder] tweaked docs
fabpot authored
51 [1]: http://api.symfony.com/2.5/Symfony/Component/Finder/SplFileInfo.html
52 [2]: http://php.net/splfileinfo
7e80874 @xabbuh link to https://symfony.com where possible
xabbuh authored
53 [3]: https://symfony.com/doc/current/components/finder.html#usage
Something went wrong with that request. Please try again.