|
| 1 | +<?php |
| 2 | +require_once(__DIR__ . '/../vendor/autoload.php'); |
| 3 | + |
| 4 | +use League\Flysystem\Filesystem; |
| 5 | +use League\Flysystem\Memory\MemoryAdapter as Adapter; |
| 6 | +use Flyfinder\Finder; |
| 7 | +use Flyfinder\Path; |
| 8 | +use Flyfinder\Specification\IsHidden; |
| 9 | +use Flyfinder\Specification\HasExtension; |
| 10 | +use Flyfinder\Specification\InPath; |
| 11 | + |
| 12 | +/* |
| 13 | + * First create a new Filesystem and add the FlySystem plugin |
| 14 | + * In this example we are using a filesystem with the memory adapter |
| 15 | + */ |
| 16 | +$filesystem = new Filesystem(new Adapter()); |
| 17 | +$filesystem->addPlugin(new Finder()); |
| 18 | + |
| 19 | +// Create some demo files |
| 20 | +$filesystem->write('test.txt', 'test'); |
| 21 | +$filesystem->write('.hiddendir/.test.txt', 'test'); |
| 22 | +$filesystem->write('.hiddendir/found.txt', 'test'); |
| 23 | +$filesystem->write('.hiddendir/normaldir/example.txt', 'test'); |
| 24 | + |
| 25 | +/* |
| 26 | + * In order to tell FlyFinder what to find, you need to give it a specification |
| 27 | + * In this example the specification will be satisfied by *.txt files |
| 28 | + * within the .hidden directory and its subdirectories that are not hidden |
| 29 | + */ |
| 30 | +$isHidden = new IsHidden(); |
| 31 | +$hasExtension = new HasExtension(['txt']); |
| 32 | +$inPath = new InPath(new Path('.hiddendir')); |
| 33 | +$specification = $inPath->andSpecification($hasExtension)->andSpecification($isHidden->notSpecification()); |
| 34 | + |
| 35 | +//FlyFinder will yield a generator object with the files that are found |
| 36 | +$generator = $filesystem->find($specification); |
| 37 | + |
| 38 | +$result = []; |
| 39 | + |
| 40 | +foreach ($generator as $value) { |
| 41 | + $result[] = $value; |
| 42 | +} |
0 commit comments