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