ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DefaultRenderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\UI\Implementation;
22 
27 use LogicException;
28 
33 class DefaultRenderer implements Renderer
34 {
38  private array $contexts = [];
39 
40  public function __construct(
41  private Render\Loader $component_renderer_loader,
42  private JavaScriptBinding $java_script_binding,
43  private \ILIAS\Language\Language $language,
44  ) {
45  }
46 
50  public function render($component, ?Renderer $root = null)
51  {
52  $this->language->loadLanguageModule('ui');
53 
54  $root = $root ?? $this;
55 
56  if (is_array($component)) {
57  $out = '';
58  foreach ($component as $_component) {
59  $out .= $root->render($_component);
60  }
61  return $out;
62  }
63 
64  try {
65  $this->pushContext($component);
66  $renderer = $this->getRendererFor($component);
67  $out = $renderer->render($component, $root);
68  } finally {
69  $this->popContext();
70  }
71 
72  return $out;
73  }
74 
78  public function renderAsync($component, ?Renderer $root = null)
79  {
80  $root = $root ?? $this;
81 
82  $out = '';
83  if (is_array($component)) {
84  foreach ($component as $_component) {
85  $out .= $root->renderAsync($_component);
86  }
87  } else {
88  $out = $this->render($component, $root) . $this->java_script_binding->getOnLoadCodeAsync();
89  }
90  return $out;
91  }
92 
101  protected function getRendererFor(Component $component): ComponentRenderer
102  {
103  return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
104  }
105 
112  protected function getContexts(): array
113  {
114  return $this->contexts;
115  }
116 
120  protected function pushContext(Component $component): void
121  {
122  $this->contexts[] = $component;
123  }
124 
129  protected function popContext(): void
130  {
131  array_pop($this->contexts);
132  }
133 }
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
pushContext(Component $component)
Adds a component to the current context stack.
$renderer
Interface Observer Contains several chained tasks and infos about them.
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...
popContext()
Removes the most recently added component from the current context stack.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private Render\Loader $component_renderer_loader, private JavaScriptBinding $java_script_binding, private \ILIAS\Language\Language $language,)
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()
Returns the current context stack, where most recently added components are last. ...
Provides methods to interface with javascript.
getRendererFor(Component $component)
Get a renderer for a certain Component class.
language()
description: > Example for rendring a language glyph.
Definition: language.php:41