1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_templates; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use ArrayAccess, IteratorAggregate, Traversable, ArrayIterator; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Abstraction of HTML element - this is compact class which only needs extending |
11
|
|
|
* @author Adam Dornak original |
12
|
|
|
* @author Petr Plsek refactored |
13
|
|
|
*/ |
14
|
|
|
abstract class AHtmlElement implements Interfaces\IHtmlElement, ArrayAccess, IteratorAggregate |
15
|
|
|
{ |
16
|
|
|
use HtmlElement\THtmlElement; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Alias for render() - for using by re-typing |
20
|
|
|
* @return string |
21
|
|
|
*/ |
22
|
1 |
|
public final function __toString() |
23
|
|
|
{ |
24
|
1 |
|
return $this->render(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Implementing ArrayAccess |
29
|
|
|
* @param string|int|null $offset |
30
|
|
|
* @param Interfaces\IHtmlElement|string $value |
31
|
|
|
*/ |
32
|
1 |
|
public final function offsetSet($offset, $value): void |
33
|
|
|
{ |
34
|
1 |
|
$this->addChild($value, $offset); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Implementing ArrayAccess |
39
|
|
|
* @param string|int $offset |
40
|
|
|
* @return bool |
41
|
|
|
*/ |
42
|
1 |
|
public final function offsetExists($offset): bool |
43
|
|
|
{ |
44
|
1 |
|
return $this->__isset($offset); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Implementing ArrayAccess |
49
|
|
|
* @param string|int $offset |
50
|
|
|
*/ |
51
|
1 |
|
public final function offsetUnset($offset): void |
52
|
|
|
{ |
53
|
1 |
|
$this->removeChild($offset); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Implementing ArrayAccess |
58
|
|
|
* @param string|int $offset |
59
|
|
|
* @return Interfaces\IHtmlElement|null |
60
|
|
|
*/ |
61
|
|
|
#[\ReturnTypeWillChange] |
62
|
1 |
|
public final function offsetGet($offset) |
63
|
|
|
{ |
64
|
1 |
|
return $this->__get($offset); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Implementing IteratorAggregate |
69
|
|
|
* Return all children as array iterator |
70
|
|
|
* @return Traversable<Interfaces\IHtmlElement> |
71
|
|
|
*/ |
72
|
1 |
|
public function getIterator(): Traversable |
73
|
|
|
{ |
74
|
1 |
|
return new ArrayIterator($this->children); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Implementing Countable |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
1 |
|
public final function count(): int |
82
|
|
|
{ |
83
|
1 |
|
return count($this->children); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|