1 | <?php |
||
28 | final class Environment implements EnvironmentInterface, ConfigurableEnvironmentInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var ExtensionInterface[] |
||
32 | */ |
||
33 | private $extensions = []; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $extensionsInitialized = false; |
||
39 | |||
40 | /** |
||
41 | * @var PrioritizedList<BlockParserInterface> |
||
42 | */ |
||
43 | private $blockParsers; |
||
44 | |||
45 | /** |
||
46 | * @var PrioritizedList<InlineParserInterface> |
||
47 | */ |
||
48 | private $inlineParsers; |
||
49 | |||
50 | /** |
||
51 | * @var array<string, PrioritizedList<InlineParserInterface>> |
||
52 | */ |
||
53 | private $inlineParsersByCharacter = []; |
||
54 | |||
55 | /** |
||
56 | * @var PrioritizedList<DocumentProcessorInterface> |
||
57 | */ |
||
58 | private $documentProcessors; |
||
59 | |||
60 | /** |
||
61 | * @var PrioritizedList<InlineProcessorInterface> |
||
62 | */ |
||
63 | private $inlineProcessors; |
||
64 | |||
65 | /** |
||
66 | * @var array<string, PrioritizedList<BlockRendererInterface>> |
||
67 | */ |
||
68 | private $blockRenderersByClass = []; |
||
69 | |||
70 | /** |
||
71 | * @var array<string, PrioritizedList<InlineRendererInterface>> |
||
72 | */ |
||
73 | private $inlineRenderersByClass = []; |
||
74 | |||
75 | /** |
||
76 | * @var Configuration |
||
77 | */ |
||
78 | private $config; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | private $inlineParserCharacterRegex; |
||
84 | |||
85 | 2055 | public function __construct(array $config = []) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 1953 | public function mergeConfig(array $config = []) |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 6 | public function setConfig(array $config = []) |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | 1959 | public function getConfig($key = null, $default = null) |
|
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | 1953 | public function addBlockParser(BlockParserInterface $parser, $priority = 0) |
|
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | */ |
||
139 | 1953 | public function addInlineParser(InlineParserInterface $parser, $priority = 0) |
|
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | 1950 | public function addInlineProcessor(InlineProcessorInterface $processor, $priority = 0) |
|
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | 9 | public function addDocumentProcessor(DocumentProcessorInterface $processor, $priority = 0) |
|
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | 1950 | public function addBlockRenderer($blockClass, BlockRendererInterface $blockRenderer, $priority = 0) |
|
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | 1950 | public function addInlineRenderer($inlineClass, InlineRendererInterface $renderer, $priority = 0) |
|
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | 1959 | public function getBlockParsers() |
|
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | */ |
||
230 | 1677 | public function getInlineParsersForCharacter($character) |
|
240 | |||
241 | /** |
||
242 | * {@inheritdoc} |
||
243 | */ |
||
244 | 1674 | public function getInlineProcessors() |
|
250 | |||
251 | /** |
||
252 | * {@inheritdoc} |
||
253 | */ |
||
254 | 1950 | public function getDocumentProcessors() |
|
260 | |||
261 | /** |
||
262 | * {@inheritdoc} |
||
263 | */ |
||
264 | 1953 | public function getBlockRenderersForClass($blockClass) |
|
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | 1674 | public function getInlineRenderersForClass($inlineClass) |
|
288 | |||
289 | /** |
||
290 | * Get all registered extensions |
||
291 | * |
||
292 | * @return ExtensionInterface[] |
||
293 | */ |
||
294 | 12 | public function getExtensions() |
|
298 | |||
299 | /** |
||
300 | * Add a single extension |
||
301 | * |
||
302 | * @param ExtensionInterface $extension |
||
303 | * |
||
304 | * @return $this |
||
305 | */ |
||
306 | 1956 | public function addExtension(ExtensionInterface $extension) |
|
314 | |||
315 | 2025 | private function initializeExtensions() |
|
333 | |||
334 | 1983 | private function injectEnvironmentAndConfigurationIfNeeded($object) |
|
344 | |||
345 | /** |
||
346 | * @return Environment |
||
347 | */ |
||
348 | 1947 | public static function createCommonMarkEnvironment() |
|
349 | { |
||
350 | 1947 | $environment = new static(); |
|
351 | 1947 | $environment->addExtension(new CommonMarkCoreExtension()); |
|
352 | 1947 | $environment->mergeConfig([ |
|
353 | 1298 | 'renderer' => [ |
|
354 | 649 | 'block_separator' => "\n", |
|
355 | 'inner_separator' => "\n", |
||
356 | 'soft_break' => "\n", |
||
357 | ], |
||
358 | 'safe' => false, // deprecated option |
||
359 | 1947 | 'html_input' => self::HTML_INPUT_ALLOW, |
|
360 | 'allow_unsafe_links' => true, |
||
361 | 1947 | 'max_nesting_level' => INF, |
|
362 | ]); |
||
363 | |||
364 | 1947 | return $environment; |
|
365 | } |
||
366 | |||
367 | /** |
||
368 | * {@inheritdoc} |
||
369 | */ |
||
370 | 1548 | public function getInlineParserCharacterRegex() |
|
374 | |||
375 | 2025 | private function buildInlineParserCharacterRegex() |
|
387 | |||
388 | /** |
||
389 | * @param string $message |
||
390 | * |
||
391 | * @throws \RuntimeException |
||
392 | */ |
||
393 | 2028 | private function assertUninitialized($message) |
|
399 | } |
||
400 |