1 | <?php |
||
25 | final class HtmlRenderer implements ElementRendererInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var EnvironmentInterface |
||
29 | */ |
||
30 | protected $environment; |
||
31 | |||
32 | /** |
||
33 | * @param EnvironmentInterface $environment |
||
34 | */ |
||
35 | 2082 | public function __construct(EnvironmentInterface $environment) |
|
39 | |||
40 | /** |
||
41 | * @param string $option |
||
42 | * @param mixed $default |
||
43 | * |
||
44 | * @return mixed|null |
||
45 | */ |
||
46 | 2061 | public function getOption(string $option, $default = null) |
|
50 | |||
51 | /** |
||
52 | * @param AbstractInline $inline |
||
53 | * |
||
54 | * @throws \RuntimeException |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 1779 | public function renderInline(AbstractInline $inline): string |
|
59 | { |
||
60 | 1779 | $renderers = $this->environment->getInlineRenderersForClass(\get_class($inline)); |
|
61 | |||
62 | /** @var InlineRendererInterface $renderer */ |
||
63 | 1779 | foreach ($renderers as $renderer) { |
|
64 | 1776 | if (($result = $renderer->render($inline, $this)) !== null) { |
|
65 | 1776 | return $result; |
|
66 | } |
||
67 | } |
||
68 | |||
69 | 3 | throw new \RuntimeException('Unable to find corresponding renderer for inline type ' . \get_class($inline)); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param AbstractInline[] $inlines |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 1776 | public function renderInlines(iterable $inlines): string |
|
86 | |||
87 | /** |
||
88 | * @param AbstractBlock $block |
||
89 | * @param bool $inTightList |
||
90 | * |
||
91 | * @throws \RuntimeException |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | 2067 | public function renderBlock(AbstractBlock $block, bool $inTightList = false): string |
|
96 | { |
||
97 | 2067 | $renderers = $this->environment->getBlockRenderersForClass(\get_class($block)); |
|
98 | |||
99 | /** @var BlockRendererInterface $renderer */ |
||
100 | 2067 | foreach ($renderers as $renderer) { |
|
101 | 2064 | if (($result = $renderer->render($block, $this, $inTightList)) !== null) { |
|
102 | 2064 | return $result; |
|
103 | } |
||
104 | } |
||
105 | |||
106 | 3 | throw new \RuntimeException('Unable to find corresponding renderer for block type ' . \get_class($block)); |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param AbstractBlock[] $blocks |
||
111 | * @param bool $inTightList |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 2061 | public function renderBlocks(iterable $blocks, bool $inTightList = false): string |
|
126 | } |
||
127 |