1 | <?php |
||
33 | abstract class ComponentAbstract implements ComponentInterface |
||
34 | { |
||
35 | /** |
||
36 | * Array of dom attributes |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $dom_attributes = array(); |
||
41 | /** |
||
42 | * Array of component scripts |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $component_scripts = array(); |
||
47 | /** |
||
48 | * Name of DOM attribute |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $dom_attribute_name; |
||
53 | /** |
||
54 | * Loaded Component Method object |
||
55 | * |
||
56 | * @var object |
||
57 | */ |
||
58 | protected $methodProvider; |
||
59 | |||
60 | /** |
||
61 | * Component Constructor |
||
62 | */ |
||
63 | 64 | public function __construct() |
|
68 | |||
69 | /** |
||
70 | * Call passes all calls to no existing methods to self::methodProvider |
||
71 | * |
||
72 | * @param string $method |
||
73 | * @param array $args |
||
74 | * @throws InvalidComponentMethodException |
||
75 | */ |
||
76 | 52 | public function __call( string $method, $args) |
|
77 | { |
||
78 | 52 | if (is_object($this->methodProvider) && method_exists($this->methodProvider, $method)) { |
|
79 | 52 | array_unshift($args, 0); |
|
80 | 52 | $args[0] = &$this->dom_attributes; |
|
81 | 52 | return call_user_func_array( |
|
82 | array( |
||
83 | 52 | $this->methodProvider, |
|
84 | 52 | (string) $method |
|
85 | ), $args); |
||
86 | } else { |
||
87 | 1 | $class = is_object($this->methodProvider) ? get_class($this->methodProvider) : get_called_class(); |
|
88 | 1 | throw new InvalidComponentMethodException($method, $class); |
|
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Return DOM attribute contents |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 6 | public function getDomAttributeString(): string |
|
103 | |||
104 | /** |
||
105 | * Set class providing component methods |
||
106 | * |
||
107 | * @param string $mp |
||
108 | * @return void |
||
109 | */ |
||
110 | 64 | public function setMethodProvider( string $mp = 'DefaultMethods') |
|
116 | |||
117 | /** |
||
118 | * Does component have DOM Atributes |
||
119 | * |
||
120 | * {@inheritdoc} |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | 4 | public function hasDOMAttributes(): bool |
|
128 | |||
129 | /** |
||
130 | * Get component DOM Atributes array |
||
131 | * |
||
132 | * {@inheritdoc} |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | 22 | public function getDOMAttributesArray(): array |
|
140 | |||
141 | /** |
||
142 | * Get Component scripts |
||
143 | * |
||
144 | * {@inheritdoc} |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | 2 | public function getComponentScripts(): array |
|
152 | |||
153 | /** |
||
154 | * Add component scripts |
||
155 | * |
||
156 | * {@inheritdoc} |
||
157 | * |
||
158 | */ |
||
159 | 1 | public function addComponentScripts( string $vendor_component, string $script_name) |
|
163 | |||
164 | /** |
||
165 | * Get DOMAttr for the entity |
||
166 | * |
||
167 | * @return DOMAttr |
||
168 | */ |
||
169 | 4 | public function getDOMAttr(): DOMAttr |
|
173 | |||
174 | /** |
||
175 | * Get Dom attribute name |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | 4 | public function getDomAttributeName(): string |
|
183 | |||
184 | /** |
||
185 | * Set Dom Attribute name |
||
186 | * |
||
187 | * @param string $dom_attribute_name |
||
188 | * @return void |
||
189 | */ |
||
190 | 64 | public function setDomAttribute( string $dom_attribute_name) |
|
194 | } |
||
195 |