ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
36 {
37 $out = '';
38 if (is_array($component)) {
39 foreach ($component as $_component) {
40 $renderer = $this->getRendererFor($_component);
41 $out .= $renderer->render($_component, $this);
42 }
43 } else {
44 $renderer = $this->getRendererFor($component);
45 $out = $renderer->render($component, $this);
46 }
47
48 return $out;
49 }
50
54 public function renderAsync($component)
55 {
56 $out = '';
57
58 if (is_array($component)) {
59 foreach ($component as $_component) {
60 $out .= $this->render($_component) .
61 $this->component_renderer_loader
62 ->getRendererFactoryFor($_component)
63 ->getJSBinding()
64 ->getOnLoadCodeAsync();
65 }
66 } else {
67 $out = $this->render($component) .
68 $this->component_renderer_loader
69 ->getRendererFactoryFor($component)
70 ->getJSBinding()
71 ->getOnLoadCodeAsync();
72 }
73 return $out;
74 }
75
86 protected function getRendererFor(Component $component)
87 {
88 return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
89 }
90
95 {
96 $clone = clone $this;
97 $clone->contexts[] = $context;
98 return $clone;
99 }
100
107 protected function getContexts()
108 {
109 return $this->contexts;
110 }
111}
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...
render($component)
Render given component.If an array of components is passed, this method returns a concatenated output...
getRendererFor(Component $component)
Get a renderer for a certain Component class.
__construct(Render\Loader $component_renderer_loader)
renderAsync($component)
Same as render, except that this version also returns any javascript code bound to the on load event,...
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:25