1 | <?php |
||
21 | abstract class SVGElement implements ContainerInterface, ElementFactoryInterface |
||
22 | { |
||
23 | use ElementTrait, ChildTrait; |
||
24 | |||
25 | private static $notConvertable = ['diffuseConstant', 'pointsAtX', 'pointsAtY', 'pointsAtZ', 'limitingConeAngle', 'tableValues', 'filterUnits', 'gradientUnits', 'viewBox', 'repeatCount', 'attributeName', 'attributeType', 'stdDeviation']; |
||
26 | |||
27 | /** |
||
28 | * @var XMLDocumentInterface | ElementInterface | ElementFactoryInterface | ContainerInterface |
||
29 | */ |
||
30 | protected $root; |
||
31 | |||
32 | /** |
||
33 | * @var XMLDocumentInterface | ElementInterface | ElementFactoryInterface | ContainerInterface |
||
34 | */ |
||
35 | protected $element; |
||
36 | |||
37 | public function __construct(ElementInterface $parent) |
||
38 | { |
||
39 | $this->child = new ElementStorage(); |
||
40 | $this->root = $parent; |
||
|
|||
41 | $this->element = $this->createElement($this->getName()); |
||
42 | $this->root->append($this); |
||
43 | } |
||
44 | |||
45 | public function createElement($name, $value = null, $attributes = []) |
||
46 | { |
||
47 | return $this->root->createElement($name, $value, $attributes); |
||
48 | } |
||
49 | |||
50 | abstract public function getName(); |
||
51 | |||
52 | final public function getRoot() |
||
53 | { |
||
54 | return $this->root; |
||
55 | } |
||
56 | |||
57 | final public function getElement() |
||
58 | { |
||
59 | return $this->element; |
||
60 | } |
||
61 | |||
62 | public function allAttributes(array $except = []) |
||
63 | { |
||
64 | return $this->element->attributes($except); |
||
65 | } |
||
66 | |||
67 | public function __get($name) |
||
68 | { |
||
69 | if ($name === 'filterUrl' || $name === 'fillUrl') { |
||
70 | return $this->getIdFromUrl($name); |
||
71 | } |
||
72 | |||
73 | $name = Inflector::camel2dash($name); |
||
74 | $value = $this->element->getAttribute($name); |
||
75 | if ($value === '') { |
||
76 | $value = $this->getXLinkAttribute($name); |
||
77 | } |
||
78 | |||
79 | return $value === '' ? null : $value; |
||
80 | } |
||
81 | |||
82 | public function __set($name, $value) |
||
83 | { |
||
84 | if ($name === 'id' && $value === null) { |
||
85 | $this->element->setAttribute($name, Identifier::random('__' . $this->getName(), 5)); |
||
86 | |||
87 | return; |
||
88 | } |
||
89 | |||
90 | if ($value === null || $value === false || $value === '') { |
||
91 | return; |
||
92 | } |
||
93 | |||
94 | if ($name === 'filterUrl' || $name === 'fillUrl') { |
||
95 | $this->handleUrlPostfixAttribute($name, $value); |
||
96 | } |
||
97 | |||
98 | $name = $this->convertAttributeName($name); |
||
99 | $this->element->setAttribute($name, $value); |
||
100 | } |
||
101 | |||
102 | public function getXLinkAttribute($name) |
||
106 | |||
107 | /** |
||
108 | * @param $name |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | private function convertAttributeName($name) |
||
116 | |||
117 | /** |
||
118 | * @inheritdoc |
||
119 | */ |
||
120 | public function apply(array $assoc) |
||
130 | |||
131 | protected function setAttribute($name, $value, $xLink = false) |
||
132 | { |
||
133 | if ($xLink === true) { |
||
134 | $this->element->setAttributeNS('xlink', $name, $value); |
||
135 | } else { |
||
136 | $this->element->setAttribute($name, $value); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | protected function selfRemove() |
||
144 | |||
145 | protected function getSVG() |
||
158 | |||
159 | /** |
||
160 | * @param $attribute |
||
161 | * @param $value |
||
162 | */ |
||
163 | private function handleUrlPostfixAttribute(&$attribute, &$value) |
||
170 | |||
171 | private function getIdFromUrl($attribute) |
||
176 | } |
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..