1 | <?php |
||
29 | abstract class SVGElement implements ContainerInterface, ElementFactoryInterface |
||
30 | { |
||
31 | use ElementTrait, ChildTrait; |
||
32 | |||
33 | /** |
||
34 | * This attribute will not be converted. |
||
35 | * |
||
36 | * @see SVGElement::__get; |
||
37 | * @var array |
||
38 | */ |
||
39 | private static $notConvertable = ['patternContentUnits', 'patternTransform', 'patternUnits', 'diffuseConstant', 'pointsAtX', 'pointsAtY', 'pointsAtZ', 'limitingConeAngle', 'tableValues', 'filterUnits', 'gradientUnits', 'viewBox', 'repeatCount', 'attributeName', 'attributeType', 'stdDeviation']; |
||
40 | |||
41 | /** |
||
42 | * The parent of `$element`. |
||
43 | * |
||
44 | * @var XMLDocumentInterface | ElementFactoryInterface | ContainerInterface |
||
45 | */ |
||
46 | protected $root; |
||
47 | |||
48 | /** |
||
49 | * The element itself. |
||
50 | * |
||
51 | * @var XMLDocumentInterface | ElementFactoryInterface | ContainerInterface |
||
52 | */ |
||
53 | protected $element; |
||
54 | |||
55 | 149 | public function __construct(ElementInterface $parent) |
|
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | 149 | public function createElement($name, $value = null, $attributes = []) |
|
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | abstract public function getName(); |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | 27 | final public function getRoot() |
|
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | 149 | final public function getElement() |
|
91 | |||
92 | /** |
||
93 | * @param string[] $except |
||
94 | * |
||
95 | * @see XMLDocumentInterface::attributes() |
||
96 | * @return array |
||
97 | */ |
||
98 | 9 | public function allAttributes(array $except = []) |
|
102 | |||
103 | /** |
||
104 | * In order to have short access to the attributes of an element. Any attribute can be obtained as a public |
||
105 | * property object. Attributes that are written with a hyphen can be obtained through a simple conversion. |
||
106 | * |
||
107 | * ```php |
||
108 | * // ... |
||
109 | * |
||
110 | * echo $circle->strokeWidth; // Property strokeWidth will be transformed into stroke-width and so on. |
||
111 | * echo $blur->stdDeviation; // Property stdDeviation will not converted into std-deviation. |
||
112 | * ``` |
||
113 | * |
||
114 | * For properties `$fill` and `$filter` will be returned something like this `url(#idTheRefToElement)`. In order to |
||
115 | * have direct access to `idTheRefToElement` part, |
||
116 | * ```php |
||
117 | * // ... |
||
118 | * $circle->filter = "url(#someFilterId)"; |
||
119 | * $id = $circle->filterUrl; |
||
120 | * echo $id; // will print someFilterId and same story with fillUrl |
||
121 | * ``` |
||
122 | * You can also have access to attributes with `xlink` namespace as mentioned above. |
||
123 | * For example you need to get `xlink:href` value. If given element doest not have `href` attribute (with no |
||
124 | * namespace prefix) it will try to get `xlink:href`. |
||
125 | * ```php |
||
126 | * $id = $mPath->href; |
||
127 | * echo $id; // will print #someHref. |
||
128 | * ``` |
||
129 | * |
||
130 | * @param string $name The name of property. |
||
131 | * |
||
132 | * @see SVGElement::$notConvertable |
||
133 | * @return null|string |
||
134 | */ |
||
135 | 109 | public function __get($name) |
|
149 | |||
150 | /** |
||
151 | * Has same propose as `__get()` and same `$filterUrl`, `$fillUrl`, name converting policy. |
||
152 | * You can generate an id for the element by assigning null. |
||
153 | * ```php |
||
154 | * // ... |
||
155 | * $circle->id = null; |
||
156 | * echo $circle->id; // will print something like this __circle12345. |
||
157 | * ``` |
||
158 | * |
||
159 | * @param string $name The name of property. |
||
160 | * @param mixed $value The value of property. |
||
161 | */ |
||
162 | 117 | public function __set($name, $value) |
|
181 | |||
182 | /** |
||
183 | * @param string $name The local name of `xlink` namespaced attribute. |
||
184 | * |
||
185 | * @return string The value of attribute. |
||
186 | */ |
||
187 | 81 | public function getXLinkAttribute($name) |
|
191 | |||
192 | /** |
||
193 | * @param string $name The local name of `xlink` attribute. |
||
194 | * @param mixed $value The value of attribute. |
||
195 | */ |
||
196 | 1 | public function setXLinkAttribute($name, $value) |
|
200 | |||
201 | /** |
||
202 | * If attribute name is convertable converts it from camelCase to dashed. |
||
203 | * |
||
204 | * @param string $name The string to convert. |
||
205 | * |
||
206 | * @return string The converted string. |
||
207 | */ |
||
208 | 120 | private function convertAttributeName($name) |
|
212 | |||
213 | /** |
||
214 | * @inheritdoc |
||
215 | */ |
||
216 | 50 | public function apply(array $assoc) |
|
226 | |||
227 | /** |
||
228 | * It removes the object itself from the DOM and from the list of the children of its parent. |
||
229 | */ |
||
230 | 3 | protected function selfRemove() |
|
234 | |||
235 | /** |
||
236 | * @return SVG The root element of hierarchy. |
||
237 | */ |
||
238 | 3 | protected function getSVG() |
|
251 | |||
252 | /** |
||
253 | * Returns standard `defs` element for `svg`. |
||
254 | * |
||
255 | * @param ElementInterface $container Where to search `defs` element. |
||
256 | * |
||
257 | * @return Defs The `defs` element. |
||
258 | */ |
||
259 | 61 | protected static function getDefs(ElementInterface $container) |
|
274 | |||
275 | /** |
||
276 | * @inheritdoc |
||
277 | */ |
||
278 | 2 | public function copy(array $apply = [], array $ignore = [], ContainerInterface $parent = null) |
|
279 | { |
||
280 | /** @var SVGElement $instance */ |
||
281 | 2 | $instance = (new Instantiator())->instantiate(get_class($this)); |
|
282 | 2 | $instance->root = $parent === null ? $this->getRoot() : $parent; |
|
283 | 2 | $instance->child = new ElementStorage(); |
|
284 | 2 | $instance->element = $this->createElement($this->getName()); |
|
285 | 2 | $instance->id = null; |
|
286 | |||
287 | 2 | if ($instance instanceof TransformInterface && $this instanceof Transformable) { |
|
288 | $instance->transformImpl = Transform::newInstance($this->getTransformAttribute()); |
||
289 | } |
||
290 | 2 | $ignore[] = 'id'; |
|
291 | 2 | $apply = array_merge($this->allAttributes($ignore), $apply); |
|
292 | 2 | $instance->apply($apply); |
|
293 | 2 | $parent === null ? $this->root->append($instance) : $parent->append($instance); |
|
294 | |||
295 | 2 | return $instance; |
|
296 | } |
||
297 | |||
298 | /** |
||
299 | * Places the `$value` into `url(#$value)` if `url(#` is not present. |
||
300 | * |
||
301 | * @param string $attribute The `$filterUrl` or `$fillUrl` properties. |
||
302 | * @param string $value The wrapped string. |
||
303 | */ |
||
304 | 23 | private function handleUrlPostfixAttribute(&$attribute, &$value) |
|
311 | |||
312 | /** |
||
313 | * Retrieves the id from the `url(#id)` string. |
||
314 | * |
||
315 | * @param string $attribute The `$filterUrl` or `$fillUrl` properties. |
||
316 | * |
||
317 | * @return string The extracted string. |
||
318 | */ |
||
319 | 1 | private function getIdFromUrl($attribute) |
|
324 | } |
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..