ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
13use ILIAS\UI\Factory as RootFactory;
14
19class DefaultRenderer implements Renderer {
23 private $ui_factory;
24
28 private $cache = array();
29
33 private $tpl_factory;
34
39
43 private $lng;
44
48 private $js_binding;
49
51 $this->ui_factory = $ui_factory;
52 $this->tpl_factory = $tpl_factory;
53 $this->resource_registry = $resource_registry;
54 $this->lng = $lng;
55 $this->js_binding = $js_binding;
56 }
57
61 public function render(Component $component) {
62 $renderer = $this->getRendererFor(get_class($component));
63 return $renderer->render($component, $this);
64 }
65
76 public function getRendererFor($class) {
77 if (array_key_exists($class, $this->cache)) {
78 return $this->cache[$class];
79 }
80 $renderer = $this->instantiateRendererFor($class);
81 $renderer->registerResources($this->resource_registry);
82 $this->cache[$class] = $renderer;
83 return $renderer;
84 }
85
95 public function instantiateRendererFor($class) {
96 $renderer_class = $this->getRendererNameFor($class);
97 if (!class_exists($renderer_class)) {
98 throw new \LogicException("No rendered for '".$class."' found.");
99 }
100 return new $renderer_class($this->ui_factory, $this->tpl_factory, $this->lng, $this->js_binding);
101 }
102
109 public function getRendererNameFor($class) {
110 $parts = explode("\\", $class);
111 $parts[count($parts)-1] = "Renderer";
112 return implode("\\", $parts);
113 }
114}
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 ...
getRendererFor($class)
Get a renderer for a certain Component class.
instantiateRendererFor($class)
Instantiate a renderer for a certain Component class.
render(Component $component)
@inheritdocs
getRendererNameFor($class)
Get the class name for the renderer of Component class.
__construct(RootFactory $ui_factory, TemplateFactory $tpl_factory, ResourceRegistry $resource_registry, \ilLanguage $lng, JavaScriptBinding $js_binding)
language handling
A component is the most general form of an entity in the UI.
Definition: Component.php:13
This is how the factory for UI elements looks.
Definition: Factory.php:15
An entity that renders components to a string output.
Provides methods to interface with javascript.
Registry for resources required by rendered output like Javascript or CSS.
Interface for a factory that provides templates.
An entity that renders components to a string output.
Definition: Renderer.php:12