|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* An iterator interface over the Leagues flysystem. |
|
4
|
|
|
* Copyright (c) 2021, 2015 Richard Klees <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This software is licensed under GPLv3. You should have received |
|
7
|
|
|
* a copy of the along with the code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Lechimp\Flightcontrol; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* An iterator on a directory. |
|
14
|
|
|
*/ |
|
15
|
|
|
class DirectoryIterator extends Iterator |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var FixedFDirectory a |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $directory; |
|
21
|
|
|
|
|
22
|
18 |
|
public function __construct(FixedFDirectory $directory) |
|
23
|
|
|
{ |
|
24
|
18 |
|
$this->directory = $directory; |
|
25
|
18 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Iterate on the contents of the this iterator. |
|
29
|
|
|
*/ |
|
30
|
6 |
|
public function iterateOn() : Iterator |
|
31
|
|
|
{ |
|
32
|
6 |
|
return new SubIterator($this); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get an iterator for every content in the current iterator |
|
37
|
|
|
* for which the provided predicate returns true. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Closure $predicate (a -> Bool) |
|
40
|
|
|
*/ |
|
41
|
10 |
|
public function filter(\Closure $predicate) : Iterator |
|
42
|
|
|
{ |
|
43
|
10 |
|
return new DirectoryIterator($this->directory->filter($predicate)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Map a function over the objects inside the iterator. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Closure $trans a -> b |
|
50
|
|
|
*/ |
|
51
|
6 |
|
public function map(\Closure $trans) : Iterator |
|
52
|
|
|
{ |
|
53
|
6 |
|
return new DirectoryIterator( |
|
54
|
6 |
|
$this->directory->map($trans) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Define the function to be iterated with and close this level |
|
60
|
|
|
* of iteration. |
|
61
|
|
|
* |
|
62
|
|
|
* @param \Closure $iteration a -> File|Directory -> a |
|
63
|
|
|
* @return mixed |
|
64
|
|
|
*/ |
|
65
|
18 |
|
public function fold($start_value, $iteration) |
|
66
|
|
|
{ |
|
67
|
18 |
|
return $this->directory->fold($start_value, $iteration)->contents(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|