1 | <?php |
||
17 | class BaseCollection extends Component implements ArrayAccess, Countable, Iterator, IComponent |
||
18 | { |
||
19 | const ERROR_INVALID_TYPE_ARG = 'Provided value must be an object instance of "%s", type "%s" is found'; |
||
20 | const ERROR_INVALID_INSTANCE_ARG = 'Provided value must be an instance of "%s", not an instance of "%s"'; |
||
21 | const ERROR_INVALID_TYPE_RETURN = 'Retrieved value is not an instance of "%s"'; |
||
22 | |||
23 | /** @var int */ |
||
24 | protected $position = 0; |
||
25 | |||
26 | /** @var IComponent[] */ |
||
27 | protected $components = []; |
||
28 | |||
29 | /** @var null|string */ |
||
30 | protected $tag = null; |
||
31 | |||
32 | /** @var array */ |
||
33 | protected $attributes = []; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $indentation = ''; |
||
37 | |||
38 | /** |
||
39 | * Collection constructor. |
||
40 | * |
||
41 | * @param string|null $tag |
||
42 | * @param array $attributes |
||
43 | */ |
||
44 | 38 | public function __construct(string $tag = null, $attributes = []) |
|
50 | |||
51 | public function rewind() |
||
55 | |||
56 | /** |
||
57 | * @return object |
||
58 | */ |
||
59 | public function current() |
||
65 | |||
66 | /** |
||
67 | * @return int |
||
68 | */ |
||
69 | public function key() |
||
73 | |||
74 | public function next() |
||
78 | |||
79 | /** |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function valid() |
||
86 | |||
87 | /** |
||
88 | * @param int|null $offset |
||
89 | * @param object $value |
||
90 | */ |
||
91 | 15 | public function offsetSet($offset, $value) |
|
99 | |||
100 | /** |
||
101 | * @param int $offset |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function offsetExists($offset) |
||
109 | |||
110 | /** |
||
111 | * @param int $offset |
||
112 | */ |
||
113 | public function offsetUnset($offset) |
||
117 | |||
118 | /** |
||
119 | * @param int $offset |
||
120 | * |
||
121 | * @return object|null |
||
122 | */ |
||
123 | public function offsetGet($offset) |
||
127 | |||
128 | /** |
||
129 | * @return int |
||
130 | */ |
||
131 | public function count() |
||
135 | |||
136 | /** |
||
137 | * @param int $num |
||
138 | * @param string $whitespace |
||
139 | */ |
||
140 | public function setIndentation(int $num, string $whitespace = ' ') |
||
148 | |||
149 | /** |
||
150 | * @param ITranslator $translator |
||
151 | */ |
||
152 | public function setTranslator(ITranslator $translator) |
||
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | 15 | public function __toString(): string |
|
175 | |||
176 | /** |
||
177 | * @param object $object |
||
178 | * @param string $className |
||
179 | * |
||
180 | * @throws InvalidArgumentException |
||
181 | */ |
||
182 | 18 | protected function verifyArgument($object, $className) |
|
183 | { |
||
184 | 18 | if ($object instanceof $className) { |
|
185 | 13 | return; |
|
186 | } |
||
187 | |||
188 | 5 | $type = gettype($object); |
|
189 | 5 | if (gettype($object) !== 'object') { |
|
190 | 5 | throw new InvalidArgumentException(sprintf(static::ERROR_INVALID_TYPE_ARG, $className, $type)); |
|
191 | } |
||
192 | |||
193 | |||
194 | throw new InvalidArgumentException( |
||
195 | sprintf(static::ERROR_INVALID_INSTANCE_ARG, $className, get_class($object)) |
||
196 | ); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @param object $object |
||
201 | * @param string $className |
||
202 | * |
||
203 | * @throws LogicException |
||
204 | */ |
||
205 | protected function verifyReturn($object, $className) |
||
213 | } |
||
214 |