1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2016-2016} Andreas Heigl<[email protected]> |
4
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
5
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
6
|
|
|
* in the Software without restriction, including without limitation the rights |
7
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
8
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
9
|
|
|
* furnished to do so, subject to the following conditions: |
10
|
|
|
* The above copyright notice and this permission notice shall be included in |
11
|
|
|
* all copies or substantial portions of the Software. |
12
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
13
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
14
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
15
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
16
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
17
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
18
|
|
|
* THE SOFTWARE. |
19
|
|
|
* |
20
|
|
|
* @author Andreas Heigl<[email protected]> |
21
|
|
|
* @copyright 2016-2016 Andreas Heigl |
22
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT-License |
23
|
|
|
* @version 0.0 |
24
|
|
|
* @since 25.03.2016 |
25
|
|
|
* @link http://github.com/heiglandreas/org.heigl.FileFinder |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace Org_Heigl\FileFinder; |
29
|
|
|
|
30
|
|
|
trait IteratorTrait |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Return the current element |
34
|
|
|
* |
35
|
|
|
* @link http://php.net/manual/en/iterator.current.php |
36
|
|
|
* @return mixed Can return any type. |
37
|
|
|
*/ |
38
|
|
|
public function current() |
39
|
|
|
{ |
40
|
|
|
return current($this->getIteratorArray()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Move forward to next element |
45
|
|
|
* |
46
|
|
|
* @link http://php.net/manual/en/iterator.next.php |
47
|
|
|
* @return void Any returned value is ignored. |
48
|
|
|
*/ |
49
|
|
|
public function next() |
50
|
|
|
{ |
51
|
|
|
next($this->getIteratorArray()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Return the key of the current element |
56
|
|
|
* |
57
|
|
|
* @link http://php.net/manual/en/iterator.key.php |
58
|
|
|
* @return mixed scalar on success, or null on failure. |
59
|
|
|
*/ |
60
|
|
|
public function key() |
61
|
|
|
{ |
62
|
|
|
return key($this->getIteratorArray()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
67
|
|
|
* Checks if current position is valid |
68
|
|
|
* |
69
|
|
|
* @link http://php.net/manual/en/iterator.valid.php |
70
|
|
|
* @return boolean The return value will be casted to boolean and then evaluated. |
71
|
|
|
* Returns true on success or false on failure. |
72
|
|
|
*/ |
73
|
|
|
public function valid() |
74
|
|
|
{ |
75
|
|
|
return false !== $this->current(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
80
|
|
|
* Rewind the Iterator to the first element |
81
|
|
|
* |
82
|
|
|
* @link http://php.net/manual/en/iterator.rewind.php |
83
|
|
|
* @return void Any returned value is ignored. |
84
|
|
|
*/ |
85
|
|
|
public function rewind() |
86
|
|
|
{ |
87
|
|
|
reset($this->getIteratorArray()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the array the iterator shall iterate over. |
92
|
|
|
* |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
|
|
abstract protected function & getIteratorArray(); |
96
|
|
|
} |