ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\UI\Implementation\DefaultRenderer Class Reference

Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the component to be rendered. More...

+ Inheritance diagram for ILIAS\UI\Implementation\DefaultRenderer:
+ Collaboration diagram for ILIAS\UI\Implementation\DefaultRenderer:

Public Member Functions

 __construct (private Render\Loader $component_renderer_loader, private JavaScriptBinding $java_script_binding,)
 
 render ($component, ?Renderer $root=null)
 Render given component.If an array of components is passed, this method returns a concatenated output of each rendered component, in the same order as given in the array
Parameters
Component|Component[]$component
?Renderer$root of renderers in the chain to be used for rendering sub components.
Returns
string
More...
 
 renderAsync ($component, ?Renderer $root=null)
 Same as render, except that this version also returns any javascript code bound to the on load event, wrapped in a script tag.All javascript code stored for rendering will be removed after this output so it will not be rendered twice if render async is called multiple times.
Parameters
Component|Component[]$component
?Renderer$root of renderers in the chain to be used for rendering sub components.
Returns
string
More...
 

Protected Member Functions

 getRendererFor (Component $component)
 Get a renderer for a certain Component class. More...
 
 getContexts ()
 Returns the current context stack, where most recently added components are last. More...
 
 pushContext (Component $component)
 Adds a component to the current context stack. More...
 
 popContext ()
 Removes the most recently added component from the current context stack. More...
 

Private Attributes

array $contexts = []
 

Detailed Description

Renderer that dispatches rendering of UI components to a Renderer found in the same namespace as the component to be rendered.

Definition at line 33 of file DefaultRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\UI\Implementation\DefaultRenderer::__construct ( private Render\Loader  $component_renderer_loader,
private JavaScriptBinding  $java_script_binding 
)

Definition at line 40 of file DefaultRenderer.php.

43  {
44  }

Member Function Documentation

◆ getContexts()

ILIAS\UI\Implementation\DefaultRenderer::getContexts ( )
protected

Returns the current context stack, where most recently added components are last.

E.g. ["FirstComponent", "SecondComponent", "ThirdComponent", ...];

Returns
Component[]

Definition at line 109 of file DefaultRenderer.php.

References ILIAS\UI\Implementation\DefaultRenderer\$contexts.

Referenced by ILIAS\UI\Implementation\DefaultRenderer\getRendererFor().

109  : array
110  {
111  return $this->contexts;
112  }
+ Here is the caller graph for this function:

◆ getRendererFor()

ILIAS\UI\Implementation\DefaultRenderer::getRendererFor ( Component  $component)
protected

Get a renderer for a certain Component class.

Either initializes a new renderer or uses a cached one initialized before.

Exceptions
LogicExceptionif no renderer could be found for component.

Definition at line 98 of file DefaultRenderer.php.

References ILIAS\UI\Implementation\DefaultRenderer\getContexts().

Referenced by ILIAS\UI\Implementation\DefaultRenderer\render().

98  : ComponentRenderer
99  {
100  return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
101  }
getContexts()
Returns the current context stack, where most recently added components are last. ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ popContext()

ILIAS\UI\Implementation\DefaultRenderer::popContext ( )
protected

Removes the most recently added component from the current context stack.

This mainly serves for testability.

Definition at line 126 of file DefaultRenderer.php.

Referenced by ILIAS\UI\Implementation\DefaultRenderer\render().

126  : void
127  {
128  array_pop($this->contexts);
129  }
+ Here is the caller graph for this function:

◆ pushContext()

ILIAS\UI\Implementation\DefaultRenderer::pushContext ( Component  $component)
protected

Adds a component to the current context stack.

This mainly serves for testability.

Definition at line 117 of file DefaultRenderer.php.

Referenced by ILIAS\UI\Implementation\DefaultRenderer\render().

117  : void
118  {
119  $this->contexts[] = $component;
120  }
+ Here is the caller graph for this function:

◆ render()

ILIAS\UI\Implementation\DefaultRenderer::render (   $component,
?Renderer  $root = null 
)

Render given component.If an array of components is passed, this method returns a concatenated output of each rendered component, in the same order as given in the array

Parameters
Component|Component[]$component
?Renderer$root of renderers in the chain to be used for rendering sub components.
Returns
string

Implements ILIAS\UI\Renderer.

Definition at line 49 of file DefaultRenderer.php.

References $out, $renderer, ILIAS\UI\Implementation\DefaultRenderer\getRendererFor(), ILIAS\UI\Implementation\DefaultRenderer\popContext(), and ILIAS\UI\Implementation\DefaultRenderer\pushContext().

Referenced by ILIAS\UI\Implementation\DefaultRenderer\renderAsync(), and DefaultRendererTest\testRenderingChainAndContextStack().

50  {
51  $root = $root ?? $this;
52 
53  if (is_array($component)) {
54  $out = '';
55  foreach ($component as $_component) {
56  $out .= $root->render($_component);
57  }
58  return $out;
59  }
60 
61  try {
62  $this->pushContext($component);
63  $renderer = $this->getRendererFor($component);
64  $out = $renderer->render($component, $root);
65  } finally {
66  $this->popContext();
67  }
68 
69  return $out;
70  }
pushContext(Component $component)
Adds a component to the current context stack.
$renderer
popContext()
Removes the most recently added component from the current context stack.
$out
Definition: buildRTE.php:24
getRendererFor(Component $component)
Get a renderer for a certain Component class.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderAsync()

ILIAS\UI\Implementation\DefaultRenderer::renderAsync (   $component,
?Renderer  $root = null 
)

Same as render, except that this version also returns any javascript code bound to the on load event, wrapped in a script tag.All javascript code stored for rendering will be removed after this output so it will not be rendered twice if render async is called multiple times.

Parameters
Component|Component[]$component
?Renderer$root of renderers in the chain to be used for rendering sub components.
Returns
string

Implements ILIAS\UI\Renderer.

Definition at line 75 of file DefaultRenderer.php.

References $out, and ILIAS\UI\Implementation\DefaultRenderer\render().

76  {
77  $root = $root ?? $this;
78 
79  $out = '';
80  if (is_array($component)) {
81  foreach ($component as $_component) {
82  $out .= $root->renderAsync($_component);
83  }
84  } else {
85  $out = $this->render($component, $root) . $this->java_script_binding->getOnLoadCodeAsync();
86  }
87  return $out;
88  }
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
$out
Definition: buildRTE.php:24
+ Here is the call graph for this function:

Field Documentation

◆ $contexts

array ILIAS\UI\Implementation\DefaultRenderer::$contexts = []
private

The documentation for this class was generated from the following file: