1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of alchemy/resource-component. |
5
|
|
|
* |
6
|
|
|
* (c) Alchemy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Alchemy\Resource\Metadata; |
13
|
|
|
|
14
|
|
|
use Assert\Assertion; |
15
|
|
|
|
16
|
|
|
class ArrayMetadataIterator implements MetadataIterator |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Metadata[] |
20
|
|
|
*/ |
21
|
|
|
private $resources; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Metadata[] $metadataResources |
25
|
|
|
*/ |
26
|
8 |
|
public function __construct(array $metadataResources) |
27
|
|
|
{ |
28
|
8 |
|
Assertion::allIsInstanceOf($metadataResources, Metadata::class); |
29
|
|
|
|
30
|
4 |
|
$this->resources = $metadataResources; |
31
|
4 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
35
|
|
|
* Move forward to next element |
36
|
|
|
* @link http://php.net/manual/en/iterator.next.php |
37
|
|
|
* @return void Any returned value is ignored. |
38
|
|
|
*/ |
39
|
4 |
|
public function next() |
40
|
|
|
{ |
41
|
4 |
|
next($this->resources); |
42
|
4 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
46
|
|
|
* Return the key of the current element |
47
|
|
|
* @link http://php.net/manual/en/iterator.key.php |
48
|
|
|
* @return mixed scalar on success, or null on failure. |
49
|
|
|
*/ |
50
|
4 |
|
public function key() |
51
|
|
|
{ |
52
|
4 |
|
return key($this->resources); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
57
|
|
|
* Checks if current position is valid |
58
|
|
|
* @link http://php.net/manual/en/iterator.valid.php |
59
|
|
|
* @return boolean The return value will be casted to boolean and then evaluated. |
60
|
|
|
* Returns true on success or false on failure. |
61
|
|
|
*/ |
62
|
4 |
|
public function valid() |
63
|
|
|
{ |
64
|
4 |
|
return key($this->resources) !== null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
69
|
|
|
* Rewind the Iterator to the first element |
70
|
|
|
* @link http://php.net/manual/en/iterator.rewind.php |
71
|
|
|
* @return void Any returned value is ignored. |
72
|
|
|
*/ |
73
|
4 |
|
public function rewind() |
74
|
|
|
{ |
75
|
4 |
|
reset($this->resources); |
76
|
4 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return Metadata |
80
|
|
|
*/ |
81
|
4 |
|
public function current() |
82
|
|
|
{ |
83
|
4 |
|
return current($this->resources); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|