1 | <?php |
||
29 | class Parser{ |
||
30 | use ClassLoaderTrait; |
||
31 | |||
32 | /** |
||
33 | * Holds the preparsed BBCode |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | public $bbcode_pre; |
||
38 | |||
39 | /** |
||
40 | * Map of Tag -> Module |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $tagmap = []; |
||
45 | |||
46 | /** |
||
47 | * Holds an array of noparse tags |
||
48 | * |
||
49 | * @var array |
||
50 | * @see \chillerlan\bbcode\Modules\Tagmap::$noparse_tags |
||
51 | */ |
||
52 | protected $noparse_tags = []; |
||
53 | |||
54 | /** |
||
55 | * Holds an array of singletags |
||
56 | * |
||
57 | * @var array |
||
58 | * @see \chillerlan\bbcode\Modules\Tagmap::$singletags |
||
59 | */ |
||
60 | protected $singletags = []; |
||
61 | |||
62 | /** |
||
63 | * Holds an array of allowed tags |
||
64 | * |
||
65 | * @var array |
||
66 | * @see \chillerlan\bbcode\Modules\Tagmap::$allowed_tags |
||
67 | */ |
||
68 | protected $allowed_tags = []; |
||
69 | |||
70 | /** |
||
71 | * Holds an array of encoder module instances |
||
72 | * |
||
73 | * @var array |
||
74 | * @see \chillerlan\bbcode\Modules\ModuleInfo::$modules |
||
75 | */ |
||
76 | protected $modules = []; |
||
77 | |||
78 | /** |
||
79 | * Holds the parser options |
||
80 | * |
||
81 | * @var \chillerlan\bbcode\ParserOptions |
||
82 | * @see \chillerlan\bbcode\Modules\Tagmap::$options |
||
83 | */ |
||
84 | protected $parserOptions; |
||
85 | |||
86 | /** |
||
87 | * Holds the parser extension instance |
||
88 | * |
||
89 | * @var \chillerlan\bbcode\ParserExtensionInterface |
||
90 | */ |
||
91 | protected $parserExtensionInterface; |
||
92 | |||
93 | /** |
||
94 | * Holds the base module instance |
||
95 | * |
||
96 | * @var \chillerlan\bbcode\Modules\BaseModuleInterface |
||
97 | */ |
||
98 | protected $baseModuleInterface; |
||
99 | |||
100 | /** |
||
101 | * Holds the current encoder module |
||
102 | * |
||
103 | * @var \chillerlan\bbcode\Modules\ModuleInterface |
||
104 | */ |
||
105 | protected $moduleInterface; |
||
106 | |||
107 | /** |
||
108 | * Holds a BBTemp instance |
||
109 | * |
||
110 | * @var \chillerlan\bbcode\BBTemp |
||
111 | */ |
||
112 | protected $BBTemp; |
||
113 | |||
114 | /** |
||
115 | * Holds the translation class for the current language |
||
116 | * |
||
117 | * @var \chillerlan\bbcode\Language\LanguageInterface |
||
118 | */ |
||
119 | protected $languageInterface; |
||
120 | |||
121 | /** |
||
122 | * Constructor. |
||
123 | * |
||
124 | * @param \chillerlan\bbcode\ParserOptions|null $options [optional] |
||
125 | */ |
||
126 | public function __construct(ParserOptions $options = null){ |
||
130 | |||
131 | /** |
||
132 | * Sets the parser options |
||
133 | * |
||
134 | * @param \chillerlan\bbcode\ParserOptions $options |
||
135 | * |
||
136 | * @throws \chillerlan\bbcode\BBCodeException |
||
137 | */ |
||
138 | public function setOptions(ParserOptions $options){ |
||
145 | |||
146 | /** |
||
147 | * Returns the current tagmap |
||
148 | */ |
||
149 | public function getTagmap():array{ |
||
153 | |||
154 | /** |
||
155 | * Returns the currently allowed tags |
||
156 | */ |
||
157 | public function getAllowed():array{ |
||
161 | |||
162 | /** |
||
163 | * Returns the noparse tags |
||
164 | */ |
||
165 | public function getNoparse():array{ |
||
169 | |||
170 | /** |
||
171 | * Returns the singletags |
||
172 | */ |
||
173 | public function getSingle():array{ |
||
177 | |||
178 | /** |
||
179 | * Encodes a BBCode string to HTML (or whatevs) |
||
180 | * |
||
181 | * @param string $bbcode |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | public function parse(string $bbcode):string{ |
||
202 | |||
203 | /** |
||
204 | * strng regexp bbcode killer |
||
205 | * |
||
206 | * @param string|array $bbcode BBCode as string or matches as array - callback from preg_replace_callback() |
||
207 | * |
||
208 | * @return string |
||
209 | * @throws \chillerlan\bbcode\BBCodeException |
||
210 | */ |
||
211 | protected function __parse($bbcode):string{ |
||
258 | |||
259 | /** |
||
260 | * The attributes parser |
||
261 | * |
||
262 | * @param string $attributes |
||
263 | * |
||
264 | * @return array |
||
265 | * @throws \chillerlan\bbcode\BBCodeException |
||
266 | */ |
||
267 | protected function getAttributes(string $attributes):array{ |
||
287 | |||
288 | /** |
||
289 | * Loads the base Interfaces (BaseModule, Language, ParserExtension) |
||
290 | * |
||
291 | * @throws \chillerlan\bbcode\BBCodeException |
||
292 | */ |
||
293 | protected function loadInterfaces(){ |
||
303 | |||
304 | /** |
||
305 | * Loads allowed/all tags |
||
306 | */ |
||
307 | protected function loadTags(){ |
||
329 | |||
330 | /** |
||
331 | * Loads the parser modules |
||
332 | * |
||
333 | * @throws \chillerlan\bbcode\BBCodeException |
||
334 | */ |
||
335 | protected function loadModules(){ |
||
354 | |||
355 | /** |
||
356 | * testing... |
||
357 | * |
||
358 | * @param $preg_error |
||
359 | * |
||
360 | * @param null $tag |
||
361 | * |
||
362 | * @throws \chillerlan\bbcode\BBCodeException |
||
363 | * @link https://github.com/chillerlan/bbcode/issues/1 |
||
364 | * @codeCoverageIgnore |
||
365 | */ |
||
366 | protected function throwPregError($preg_error, $tag = null){ |
||
387 | |||
388 | } |
||
389 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.