1 | <?php |
||
12 | class Tag extends AbstractBaseHtmlTagObject implements TagInterface |
||
13 | { |
||
14 | /** |
||
15 | * The tag name. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | private $tag; |
||
20 | |||
21 | /** |
||
22 | * The tag attributes. |
||
23 | * |
||
24 | * @var \drupol\htmltag\Attributes\AttributesInterface |
||
25 | */ |
||
26 | private $attributes; |
||
27 | |||
28 | /** |
||
29 | * The tag content. |
||
30 | * |
||
31 | * @var mixed[]|null |
||
32 | */ |
||
33 | private $content; |
||
34 | |||
35 | /** |
||
36 | * Tag constructor. |
||
37 | * |
||
38 | * @param \drupol\htmltag\Attributes\AttributesInterface $attributes |
||
39 | * The attributes object. |
||
40 | * @param string $name |
||
41 | * The tag name. |
||
42 | * @param mixed $content |
||
43 | * The content. |
||
44 | */ |
||
45 | 14 | public function __construct(AttributesInterface $attributes, $name, $content = null) |
|
46 | { |
||
47 | 14 | $this->tag = $name; |
|
48 | 14 | $this->attributes = $attributes; |
|
49 | 14 | $this->content($content); |
|
50 | 14 | } |
|
51 | |||
52 | /** |
||
53 | * @param string $name |
||
54 | * @param array $arguments |
||
55 | * |
||
56 | * @return \drupol\htmltag\Tag\TagInterface |
||
57 | */ |
||
58 | 1 | public static function __callStatic($name, array $arguments = []) |
|
59 | { |
||
60 | 1 | return new static($arguments[0], $name); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 2 | public function __toString() |
|
67 | { |
||
68 | 2 | return $this->render(); |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 3 | public function attr($name = null, ...$value) |
|
75 | { |
||
76 | 3 | if (null == $name) { |
|
|
|||
77 | 1 | return $this->attributes->render(); |
|
78 | } |
||
79 | |||
80 | 3 | if ([] == $value) { |
|
81 | 2 | return $this->attributes[$name]; |
|
82 | } |
||
83 | |||
84 | 1 | return $this->attributes[$name]->set($value); |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | 14 | public function content(...$data) |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 10 | public function render() |
|
112 | |||
113 | /** |
||
114 | * Render the tag content. |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 14 | protected function renderContent() |
|
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | 1 | public function serialize() |
|
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | 1 | public function unserialize($serialized) |
|
153 | |||
154 | /** |
||
155 | * Alter the values of an object. |
||
156 | * |
||
157 | * @param callable ...$closures |
||
158 | * A closure. |
||
159 | * |
||
160 | * @return object |
||
161 | * The object. |
||
162 | */ |
||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | 1 | public function alter(callable ...$closures) |
|
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | */ |
||
180 | 10 | protected function escape($value) |
|
192 | |||
193 | /** |
||
194 | * @return array|\drupol\htmltag\Attribute\AttributeInterface[] |
||
195 | */ |
||
196 | 1 | public function getContentAsArray() |
|
202 | } |
||
203 |