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 | 92 | public function __construct(string $tag = null, $attributes = []) |
|
50 | |||
51 | 6 | public function rewind() |
|
55 | |||
56 | /** |
||
57 | * @return object |
||
58 | */ |
||
59 | 30 | public function current() |
|
69 | |||
70 | /** |
||
71 | * @return int |
||
72 | */ |
||
73 | public function key() |
||
77 | |||
78 | 28 | public function next() |
|
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function valid() |
||
90 | |||
91 | /** |
||
92 | * @param int|null $offset |
||
93 | * @param object $value |
||
94 | */ |
||
95 | 67 | public function offsetSet($offset, $value) |
|
103 | |||
104 | /** |
||
105 | * @param int $offset |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function offsetExists($offset) |
||
113 | |||
114 | /** |
||
115 | * @param int $offset |
||
116 | */ |
||
117 | public function offsetUnset($offset) |
||
121 | |||
122 | /** |
||
123 | * @param int $offset |
||
124 | * |
||
125 | * @return object|null |
||
126 | */ |
||
127 | 6 | public function offsetGet($offset) |
|
131 | |||
132 | /** |
||
133 | * @return int |
||
134 | */ |
||
135 | 6 | public function count() |
|
139 | |||
140 | /** |
||
141 | * @param int $num |
||
142 | * @param string $whitespace |
||
143 | */ |
||
144 | 5 | public function setIndentation(int $num, string $whitespace = ' ') |
|
145 | { |
||
146 | 5 | foreach ($this->components as $component) { |
|
147 | 5 | $component->setIndentation($num + 1, $whitespace); |
|
148 | } |
||
149 | |||
150 | 5 | $this->indentation = str_repeat($whitespace, $num); |
|
151 | 5 | } |
|
152 | |||
153 | /** |
||
154 | * @param ITranslator $translator |
||
155 | */ |
||
156 | 5 | public function setTranslator(ITranslator $translator) |
|
157 | { |
||
158 | 5 | foreach ($this->components as $component) { |
|
159 | 5 | $component->setTranslator($translator); |
|
160 | } |
||
161 | 5 | } |
|
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | 15 | public function __toString(): string |
|
179 | |||
180 | /** |
||
181 | * @param object $object |
||
182 | * @param string $className |
||
183 | * |
||
184 | * @throws InvalidArgumentException |
||
185 | */ |
||
186 | 63 | protected function verifyArgument($object, $className) |
|
202 | |||
203 | /** |
||
204 | * @param object $object |
||
205 | * @param string $className |
||
206 | * |
||
207 | * @throws LogicException |
||
208 | */ |
||
209 | 30 | protected function verifyReturn($object, $className) |
|
217 | } |
||
218 |