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 
14 
19 class 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 }
getRendererFor($class)
Get a renderer for a certain Component class.
Registry for resources required by rendered output like Javascript or CSS.
An entity that renders components to a string output.
Definition: Renderer.php:12
__construct(RootFactory $ui_factory, TemplateFactory $tpl_factory, ResourceRegistry $resource_registry, \ilLanguage $lng, JavaScriptBinding $js_binding)
instantiateRendererFor($class)
Instantiate a renderer for a certain Component class.
Provides methods to interface with javascript.
Create styles array
The data for the language used.
getRendererNameFor($class)
Get the class name for the renderer of Component class.
language handling
Interface for a factory that provides templates.