1 | <?php |
||
38 | abstract class AbstractComponent implements NestableInterface { |
||
39 | /** |
||
40 | * Holds a reference of the component's attribute manger. |
||
41 | * |
||
42 | * @var AttributeManager $attributeManager |
||
43 | */ |
||
44 | private $attributeManager; |
||
45 | |||
46 | /** |
||
47 | * @var ComponentLibrary $componentLibrary |
||
48 | */ |
||
49 | private $componentLibrary; |
||
50 | |||
51 | /** |
||
52 | * The (html) id of this component. Not available before the component was opened. |
||
53 | * |
||
54 | * @var string $id |
||
55 | */ |
||
56 | private $id; |
||
57 | |||
58 | /** |
||
59 | * Name of the component |
||
60 | * |
||
61 | * @var string $name |
||
62 | */ |
||
63 | private $name; |
||
64 | |||
65 | /** |
||
66 | * @var NestingController $nestingController |
||
67 | */ |
||
68 | private $nestingController; |
||
69 | |||
70 | /** |
||
71 | * @var NestableInterface|false $parentComponent |
||
72 | */ |
||
73 | private $parentComponent; |
||
74 | |||
75 | /** |
||
76 | * @var ParserOutputHelper $parserOutputHelper |
||
77 | */ |
||
78 | private $parserOutputHelper; |
||
79 | |||
80 | /** |
||
81 | * @var ParserRequest $parserRequest |
||
82 | */ |
||
83 | private $parserRequest; |
||
84 | |||
85 | /** |
||
86 | * For every of my registered attributes holds a value. false, if not valid in supplied |
||
87 | * parserRequest. |
||
88 | * |
||
89 | * @var array $sanitizedAttributes |
||
90 | */ |
||
91 | private $sanitizedAttributes; |
||
92 | |||
93 | /** |
||
94 | * Does the actual work in the individual components. |
||
95 | * |
||
96 | * @param string $input |
||
97 | * |
||
98 | * @return string|array |
||
99 | */ |
||
100 | abstract protected function placeMe( $input ); |
||
101 | |||
102 | /** |
||
103 | * Component constructor. |
||
104 | * |
||
105 | * @param ComponentLibrary $componentLibrary |
||
106 | * @param ParserOutputHelper $parserOutputHelper |
||
107 | * @param NestingController $nestingController |
||
108 | * |
||
109 | * @throws MWException cascading {@see \BootstrapComponents\ComponentLibrary::getNameFor} |
||
110 | * or {@see \BootstrapComponents\Component::extractAttribute} |
||
111 | */ |
||
112 | 42 | public function __construct( $componentLibrary, $parserOutputHelper, $nestingController ) { |
|
126 | |||
127 | /** |
||
128 | * Returns the name of the component. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 42 | public function getComponentName() { |
|
135 | |||
136 | /** |
||
137 | * Note that id is only present after {@see AbstractComponent::parseComponent} starts execution. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | 30 | public function getId() { |
|
144 | |||
145 | /** |
||
146 | * @param ParserRequest $parserRequest ; |
||
147 | * |
||
148 | * @throws \MWException self or cascading from {@see \BootstrapComponents\Component::processArguments} |
||
149 | * or {@see \BootstrapComponents\NestingController::close} |
||
150 | * @return string|array |
||
151 | */ |
||
152 | 40 | public function parseComponent( $parserRequest ) { |
|
165 | |||
166 | /** |
||
167 | * Converts the input array to a string using glue. Removes invalid (false) entries beforehand. |
||
168 | * |
||
169 | * @param array|false $array |
||
170 | * @param string $glue |
||
171 | * |
||
172 | * @return false|string returns false on empty array, string otherwise |
||
173 | */ |
||
174 | 27 | protected function arrayToString( $array, $glue ) { |
|
185 | |||
186 | /** |
||
187 | * @return AttributeManager |
||
188 | */ |
||
189 | 29 | protected function getAttributeManager() { |
|
192 | |||
193 | /** |
||
194 | * @return ComponentLibrary |
||
195 | */ |
||
196 | 29 | protected function getComponentLibrary() { |
|
199 | |||
200 | /** |
||
201 | * @return NestingController |
||
202 | */ |
||
203 | 42 | protected function getNestingController() { |
|
206 | |||
207 | /** |
||
208 | * @return NestableInterface|false |
||
209 | */ |
||
210 | 5 | protected function getParentComponent() { |
|
213 | |||
214 | /** |
||
215 | * @return ParserOutputHelper |
||
216 | */ |
||
217 | 29 | protected function getParserOutputHelper() { |
|
220 | |||
221 | /** |
||
222 | * Returns the original parser request supplied to this component. |
||
223 | * Note, that none of the attributes nor the input were parsed with |
||
224 | * {@see \Parser::recursiveTagParse}. |
||
225 | * |
||
226 | * @return ParserRequest |
||
227 | */ |
||
228 | 6 | protected function getParserRequest() { |
|
231 | |||
232 | /** |
||
233 | * If attribute is registered, this returns the verified and parsed value for it. If not, or the |
||
234 | * verified value is false, this returns the fallback. |
||
235 | * |
||
236 | * @param string $attribute |
||
237 | * @param bool|string $fallback |
||
238 | * |
||
239 | * @return bool|string |
||
240 | */ |
||
241 | 29 | protected function getValueFor( $attribute, $fallback = false ) { |
|
247 | |||
248 | /** |
||
249 | * Parses input text from parser request. Does also some fixes to let parser detect paragraphs in content. |
||
250 | * |
||
251 | * @param ParserRequest $parserRequest |
||
252 | * @param bool $fullParse |
||
253 | * |
||
254 | * @since 1.1.0 |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | 29 | protected function prepareInput( $parserRequest, $fullParse = false ) { |
|
277 | |||
278 | /** |
||
279 | * Takes your class and style string and appends them with corresponding data from user (if present) |
||
280 | * passed in attributes. |
||
281 | * |
||
282 | * @param string|array $class |
||
283 | * @param string|array $style |
||
284 | * |
||
285 | * @return array[] containing (array)$class and (array)$style |
||
286 | */ |
||
287 | 27 | protected function processCss( $class, $style ) { |
|
298 | |||
299 | /** |
||
300 | * Performs all the mandatory actions on the parser output for the component class. |
||
301 | */ |
||
302 | 29 | private function augmentParserOutput() { |
|
311 | |||
312 | /** |
||
313 | * Initializes the attributes, id and stores the original parser request. |
||
314 | * |
||
315 | * @param ParserRequest $parserRequest |
||
316 | */ |
||
317 | 29 | private function initComponentData( $parserRequest ) { |
|
328 | |||
329 | /** |
||
330 | * For every registered attribute, sanitizes (parses and verifies) the corresponding value in supplied attributes. |
||
331 | * |
||
332 | * @param \Parser $parser |
||
333 | * @param string[] $attributes |
||
334 | * |
||
335 | * @return array |
||
336 | */ |
||
337 | 29 | private function sanitizeAttributes( $parser, $attributes ) { |
|
345 | |||
346 | /** |
||
347 | * @param NestableInterface|false $parentComponent |
||
348 | */ |
||
349 | 42 | private function storeParentComponent( $parentComponent ) { |
|
352 | } |
||
353 |