ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DefaultRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use LogicException;
28
33class DefaultRenderer implements Renderer
34{
38 private array $contexts = [];
39
40 public function __construct(
41 private Render\Loader $component_renderer_loader,
42 private JavaScriptBinding $java_script_binding,
43 private \ILIAS\Language\Language $language,
44 ) {
45 }
46
50 public function render($component, ?Renderer $root = null)
51 {
52 $this->language->loadLanguageModule('ui');
53
54 $root = $root ?? $this;
55
56 $out = '';
57 if (is_array($component)) {
58 foreach ($component as $_component) {
59 $out .= $root->render($_component);
60 }
61 return $out;
62 }
63
64 try {
65 $this->pushContext($component);
66 $renderer = $this->getRendererFor($component);
67 $out = $renderer->render($component, $root);
68 } finally {
69 $this->popContext();
70 }
71
72 return $out;
73 }
74
78 public function renderAsync($component, ?Renderer $root = null)
79 {
80 $root = $root ?? $this;
81
82 $out = '';
83 if (is_array($component)) {
84 foreach ($component as $_component) {
85 $out .= $root->renderAsync($_component);
86 }
87 } else {
88 $out = $this->render($component, $root) . $this->java_script_binding->getOnLoadCodeAsync();
89 }
90 return $out;
91 }
92
101 protected function getRendererFor(Component $component): ComponentRenderer
102 {
103 return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
104 }
105
112 protected function getContexts(): array
113 {
114 return $this->contexts;
115 }
116
120 protected function pushContext(Component $component): void
121 {
122 $this->contexts[] = $component;
123 }
124
129 protected function popContext(): void
130 {
131 array_pop($this->contexts);
132 }
133}
$out
Definition: buildRTE.php:24
$renderer
Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the ...
getContexts()
Returns the current context stack, where most recently added components are last.
pushContext(Component $component)
Adds a component to the current context stack.
popContext()
Removes the most recently added component from the current context stack.
getRendererFor(Component $component)
Get a renderer for a certain Component class.
renderAsync($component, ?Renderer $root=null)
Same as render, except that this version also returns any javascript code bound to the on load event,...
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
__construct(private Render\Loader $component_renderer_loader, private JavaScriptBinding $java_script_binding, private \ILIAS\Language\Language $language,)
A component is the most general form of an entity in the UI.
Definition: Component.php:28
An entity that renders components to a string output.
Provides methods to interface with javascript.
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.