1 | <?php |
||
39 | abstract class AbstractComponent implements NestableInterface { |
||
40 | /** |
||
41 | * Holds a reference of the component's attribute manger. |
||
42 | * |
||
43 | * @var AttributeManager $attributeManager |
||
44 | */ |
||
45 | private $attributeManager; |
||
46 | |||
47 | /** |
||
48 | * @var ComponentLibrary $componentLibrary |
||
49 | */ |
||
50 | private $componentLibrary; |
||
51 | |||
52 | /** |
||
53 | * The (html) id of this component. Not available before the component was opened. |
||
54 | * |
||
55 | * @var string $id |
||
56 | */ |
||
57 | private $id; |
||
58 | |||
59 | /** |
||
60 | * Name of the component |
||
61 | * |
||
62 | * @var string $name |
||
63 | */ |
||
64 | private $name; |
||
65 | |||
66 | /** |
||
67 | * @var NestingController $nestingController |
||
68 | */ |
||
69 | private $nestingController; |
||
70 | |||
71 | /** |
||
72 | * @var NestableInterface|false $parentComponent |
||
73 | */ |
||
74 | private $parentComponent; |
||
75 | |||
76 | /** |
||
77 | * @var ParserOutputHelper $parserOutputHelper |
||
78 | */ |
||
79 | private $parserOutputHelper; |
||
80 | |||
81 | /** |
||
82 | * @var ParserRequest $parserRequest |
||
83 | */ |
||
84 | private $parserRequest; |
||
85 | |||
86 | /** |
||
87 | * For every of my registered attributes holds a value. false, if not valid in supplied |
||
88 | * parserRequest. |
||
89 | * |
||
90 | * @var array $sanitizedAttributes |
||
91 | */ |
||
92 | private $sanitizedAttributes; |
||
93 | |||
94 | /** |
||
95 | * Does the actual work in the individual components. |
||
96 | * |
||
97 | * @param string $input |
||
98 | * |
||
99 | * @return string|array |
||
100 | */ |
||
101 | abstract protected function placeMe( $input ); |
||
102 | |||
103 | /** |
||
104 | * Component constructor. |
||
105 | * |
||
106 | * @param ComponentLibrary $componentLibrary |
||
107 | * @param ParserOutputHelper $parserOutputHelper |
||
108 | * @param NestingController $nestingController |
||
109 | * |
||
110 | * @throws MWException cascading {@see \BootstrapComponents\ComponentLibrary::getNameFor} |
||
111 | * or {@see \BootstrapComponents\Component::extractAttribute} |
||
112 | */ |
||
113 | 42 | public function __construct( $componentLibrary, $parserOutputHelper, $nestingController ) { |
|
127 | |||
128 | /** |
||
129 | * Returns the name of the component. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 42 | public function getComponentName() { |
|
136 | |||
137 | /** |
||
138 | * Note that id is only present after {@see AbstractComponent::parseComponent} starts execution. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 30 | public function getId() { |
|
145 | |||
146 | /** |
||
147 | * @param ParserRequest $parserRequest ; |
||
148 | * |
||
149 | * @throws \MWException self or cascading from {@see \BootstrapComponents\Component::processArguments} |
||
150 | * or {@see \BootstrapComponents\NestingController::close} |
||
151 | * @return string|array |
||
152 | */ |
||
153 | 40 | public function parseComponent( $parserRequest ) { |
|
166 | |||
167 | /** |
||
168 | * Converts the input array to a string using glue. Removes invalid (false) entries beforehand. |
||
169 | * |
||
170 | * @param array|false $array |
||
171 | * @param string $glue |
||
172 | * |
||
173 | * @return false|string returns false on empty array, string otherwise |
||
174 | */ |
||
175 | 28 | protected function arrayToString( $array, $glue ) { |
|
186 | |||
187 | /** |
||
188 | * @return AttributeManager |
||
189 | */ |
||
190 | 29 | protected function getAttributeManager() { |
|
193 | |||
194 | /** |
||
195 | * @return ComponentLibrary |
||
196 | */ |
||
197 | 29 | protected function getComponentLibrary() { |
|
200 | |||
201 | /** |
||
202 | * @return NestingController |
||
203 | */ |
||
204 | 42 | protected function getNestingController() { |
|
207 | |||
208 | /** |
||
209 | * @return NestableInterface|false |
||
210 | */ |
||
211 | 5 | protected function getParentComponent() { |
|
214 | |||
215 | /** |
||
216 | * @return ParserOutputHelper |
||
217 | */ |
||
218 | 29 | protected function getParserOutputHelper() { |
|
226 | |||
227 | /** |
||
228 | * Returns the original parser request supplied to this component. |
||
229 | * Note, that none of the attributes nor the input were parsed with |
||
230 | * {@see \Parser::recursiveTagParse}. |
||
231 | * |
||
232 | * @return ParserRequest |
||
233 | */ |
||
234 | 6 | protected function getParserRequest() { |
|
237 | |||
238 | /** |
||
239 | * If attribute is registered, this returns the verified and parsed value for it. If not, or the |
||
240 | * verified value is false, this returns the fallback. |
||
241 | * |
||
242 | * @param string $attribute |
||
243 | * @param bool|string $fallback |
||
244 | * |
||
245 | * @return bool|string |
||
246 | */ |
||
247 | 29 | protected function getValueFor( $attribute, $fallback = false ) { |
|
253 | |||
254 | /** |
||
255 | * Parses input text from parser request. Does also some fixes to let parser detect paragraphs in content. |
||
256 | * |
||
257 | * @param ParserRequest $parserRequest |
||
258 | * @param bool $fullParse |
||
259 | * |
||
260 | * @since 1.1.0 |
||
261 | * |
||
262 | * @return string |
||
263 | */ |
||
264 | 29 | protected function prepareInput( $parserRequest, $fullParse = false ) { |
|
283 | |||
284 | /** |
||
285 | * Takes your class and style string and appends them with corresponding data from user (if present) |
||
286 | * passed in attributes. |
||
287 | * |
||
288 | * @param string|array $class |
||
289 | * @param string|array $style |
||
290 | * |
||
291 | * @return array[] containing (array)$class and (array)$style |
||
292 | */ |
||
293 | 27 | protected function processCss( $class, $style ) { |
|
304 | |||
305 | /** |
||
306 | * Performs all the mandatory actions on the parser output for the component class. |
||
307 | */ |
||
308 | 29 | private function augmentParserOutput() { |
|
317 | |||
318 | /** |
||
319 | * Initializes the attributes, id and stores the original parser request. |
||
320 | * |
||
321 | * @param ParserRequest $parserRequest |
||
322 | */ |
||
323 | 29 | private function initComponentData( $parserRequest ) { |
|
334 | |||
335 | /** |
||
336 | * For every registered attribute, sanitizes (parses and verifies) the corresponding value in supplied attributes. |
||
337 | * |
||
338 | * @param \Parser $parser |
||
339 | * @param string[] $attributes |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | 29 | private function sanitizeAttributes( $parser, $attributes ) { |
|
351 | |||
352 | /** |
||
353 | * @param NestableInterface|false $parentComponent |
||
354 | */ |
||
355 | 42 | private function storeParentComponent( $parentComponent ) { |
|
358 | } |
||
359 |