ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DefaultRenderer.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
10
15class DefaultRenderer implements Renderer
16{
21
25 private $contexts = [];
26
27 public function __construct(Render\Loader $component_renderer_loader)
28 {
29 $this->component_renderer_loader = $component_renderer_loader;
30 }
31
35 public function render($component, ?Renderer $root = null)
36 {
37 $root = $root ?? $this;
38
39 $out = '';
40 if (is_array($component)) {
41 foreach ($component as $_component) {
42 $out .= $root->render($_component);
43 }
44 } else {
45 $renderer = $this->getRendererFor($component);
46 $out = $renderer->render($component, $root);
47 }
48
49 return $out;
50 }
51
55 public function renderAsync($component, ?Renderer $root = null)
56 {
57 $root = $root ?? $this;
58
59 $out = '';
60 if (is_array($component)) {
61 foreach ($component as $_component) {
62 $out .= $root->renderAsync($_component);
63 }
64 } else {
65 $out = $this->render($component, $root) .
66 $this->getJSCodeForAsyncRenderingFor($component);
67 }
68 return $out;
69 }
70
81 protected function getRendererFor(Component $component)
82 {
83 return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
84 }
85
92 protected function getJSCodeForAsyncRenderingFor(Component $component)
93 {
94 return $this->component_renderer_loader
95 ->getRendererFactoryFor($component)
96 ->getJSBinding()
97 ->getOnLoadCodeAsync();
98 }
99
104 {
105 $clone = clone $this;
106 $clone->contexts[] = $context;
107 return $clone;
108 }
109
116 protected function getContexts()
117 {
118 return $this->contexts;
119 }
120}
An exception for terminatinating execution or to throw for unit testing.
Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the ...
withAdditionalContext(Component $context)
Get a new renderer with an additional context.A context makes it possible to use another renderer for...
getContexts()
Get the contexts that are added via withAdditionalContext where most recently added contexts come las...
getJSCodeForAsyncRenderingFor(Component $component)
Get JS-Code for asynchronous rendering of component.
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,...
__construct(Render\Loader $component_renderer_loader)
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
A component is the most general form of an entity in the UI.
Definition: Component.php:14
An entity that renders components to a string output.
An entity that renders components to a string output.
Definition: Renderer.php:15
$context
Definition: webdav.php:26