ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
DefaultRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\UI\Implementation;
22 
26 use LogicException;
27 
32 class DefaultRenderer implements Renderer
33 {
35 
39  private array $contexts = [];
40 
41  public function __construct(Render\Loader $component_renderer_loader)
42  {
43  $this->component_renderer_loader = $component_renderer_loader;
44  }
45 
49  public function render($component, ?Renderer $root = null)
50  {
51  $root = $root ?? $this;
52 
53  $out = '';
54  if (is_array($component)) {
55  foreach ($component as $_component) {
56  $out .= $root->render($_component);
57  }
58  } else {
59  $renderer = $this->getRendererFor($component);
60  $out = $renderer->render($component, $root);
61  }
62 
63  return $out;
64  }
65 
69  public function renderAsync($component, ?Renderer $root = null)
70  {
71  $root = $root ?? $this;
72 
73  $out = '';
74  if (is_array($component)) {
75  foreach ($component as $_component) {
76  $out .= $root->renderAsync($_component);
77  }
78  } else {
79  $out = $this->render($component, $root) .
80  $this->getJSCodeForAsyncRenderingFor($component);
81  }
82  return $out;
83  }
84 
93  protected function getRendererFor(Component $component): ComponentRenderer
94  {
95  return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
96  }
97 
104  protected function getJSCodeForAsyncRenderingFor(Component $component)
105  {
106  return $this->component_renderer_loader
107  ->getRendererFactoryFor($component)
108  ->getJSBinding()
109  ->getOnLoadCodeAsync();
110  }
111 
116  {
117  $clone = clone $this;
118  $clone->contexts[] = $context;
119  return $clone;
120  }
121 
128  protected function getContexts(): array
129  {
130  return $this->contexts;
131  }
132 }
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
An entity that renders components to a string output.
Definition: Renderer.php:30
$context
Definition: webdav.php:29
getJSCodeForAsyncRenderingFor(Component $component)
Get JS-Code for asynchronous rendering of component.
withAdditionalContext(Component $context)
Get a new renderer with an additional context.A context makes it possible to use another renderer for...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderAsync($component, ?Renderer $root=null)
Same as render, except that this version also returns any javascript code bound to the on load event...
$out
Definition: buildRTE.php:24
getContexts()
Get the contexts that are added via withAdditionalContext where most recently added contexts come las...
__construct(Render\Loader $component_renderer_loader)
getRendererFor(Component $component)
Get a renderer for a certain Component class.
Loads renderers for components.
Definition: Loader.php:29