1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* micrometa |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Micrometa |
8
|
|
|
* @subpackage Jkphl\Micrometa\Ports\Item |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Jkphl\Micrometa\Ports\Item; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Item list |
41
|
|
|
* |
42
|
|
|
* @package Jkphl\Micrometa |
43
|
|
|
* @subpackage Jkphl\Micrometa\Ports |
44
|
|
|
*/ |
45
|
|
|
class ItemList implements ItemListInterface |
46
|
|
|
{ |
47
|
|
|
/** |
48
|
|
|
* Items |
49
|
|
|
* |
50
|
|
|
* @var ItemInterface[] |
51
|
|
|
*/ |
52
|
|
|
protected $items; |
53
|
|
|
/** |
54
|
|
|
* Internal pointer |
55
|
|
|
* |
56
|
|
|
* @var null |
57
|
|
|
*/ |
58
|
|
|
protected $pointer = null; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* ItemList constructor |
62
|
|
|
* |
63
|
|
|
* @param ItemInterface[] $items Items |
64
|
|
|
*/ |
65
|
1 |
|
public function __construct(array $items = []) |
66
|
|
|
{ |
67
|
1 |
|
$this->items = $items; |
68
|
1 |
|
$this->pointer = 0; |
|
|
|
|
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Return the current item |
73
|
|
|
* |
74
|
|
|
* @return ItemInterface Item |
75
|
|
|
*/ |
76
|
|
|
public function current() |
77
|
|
|
{ |
78
|
|
|
return $this->items[$this->pointer]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Move forward to next element |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function next() |
87
|
|
|
{ |
88
|
|
|
++$this->pointer; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return the position of the current element |
93
|
|
|
* |
94
|
|
|
* @return mixed Position of the current element |
95
|
|
|
*/ |
96
|
|
|
public function key() |
97
|
|
|
{ |
98
|
|
|
return $this->pointer; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Checks if current position is valid |
103
|
|
|
* |
104
|
|
|
* @return boolean The current position is valid |
105
|
|
|
*/ |
106
|
|
|
public function valid() |
107
|
|
|
{ |
108
|
|
|
return isset($this->items[$this->pointer]); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Rewind the item list to the first element |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function rewind() |
117
|
|
|
{ |
118
|
|
|
$this->pointer = 0; |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Return an object representation of the item list |
123
|
|
|
* |
124
|
|
|
* @return \stdClass Micro information items |
125
|
|
|
* @api |
126
|
|
|
*/ |
127
|
|
|
public function toObject() |
128
|
|
|
{ |
129
|
|
|
return new \stdClass(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Return a JSON representation of the item list |
134
|
|
|
* |
135
|
|
|
* @return string Micro information items |
136
|
|
|
* @api |
137
|
|
|
*/ |
138
|
|
|
public function toJson() |
139
|
|
|
{ |
140
|
|
|
return json_encode(new \stdClass()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Return all items, optionally of particular types |
145
|
|
|
* |
146
|
|
|
* @param array ...$types Item types |
147
|
|
|
* @return ItemListInterface Items matching the requested types |
148
|
|
|
* @api |
149
|
|
|
*/ |
150
|
|
|
public function items(...$types) |
151
|
|
|
{ |
152
|
|
|
return []; |
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Return the first item, optionally of particular types |
157
|
|
|
* |
158
|
|
|
* @param array ...$types Item types |
159
|
|
|
* @return ItemInterface Item |
160
|
|
|
* @api |
161
|
|
|
*/ |
162
|
|
|
public function item(...$types) |
163
|
|
|
{ |
164
|
|
|
return new Item(); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..