ILIAS  release_8 Revision v8.24
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 (Render\Loader $component_renderer_loader)
 
 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...
 
 withAdditionalContext (Component $context)
 Get a new renderer with an additional context.A context makes it possible to use another renderer for (some) components when they are renderer as subcomponents of a certain components. The use case that spawned this functionality is the observation, that e.g. items representing repository objects are renderer in different lists, where the individual items look different every time but are morally the same item. Another use case could be a special rendering of input fields in filters over tables.If a component wants to render itself differently in different contexts, it must implement a RendererFactory. The class \ILIAS\UI\Implementation\Render\FSLoader contains directions how to do that. More...
 
 render ($component, ?Renderer $root=null)
 Render given component. 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. More...
 
 withAdditionalContext (Component $context)
 Get a new renderer with an additional context. More...
 

Protected Member Functions

 getRendererFor (Component $component)
 Get a renderer for a certain Component class. More...
 
 getJSCodeForAsyncRenderingFor (Component $component)
 Get JS-Code for asynchronous rendering of component. More...
 
 getContexts ()
 Get the contexts that are added via withAdditionalContext where most recently added contexts come last. More...
 

Private Attributes

Render Loader $component_renderer_loader
 
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 32 of file DefaultRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\UI\Implementation\DefaultRenderer::__construct ( Render\Loader  $component_renderer_loader)

Definition at line 41 of file DefaultRenderer.php.

42 {
43 $this->component_renderer_loader = $component_renderer_loader;
44 }

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

Member Function Documentation

◆ getContexts()

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

Get the contexts that are added via withAdditionalContext where most recently added contexts come last.

Returns
Component[]

Definition at line 128 of file DefaultRenderer.php.

128 : array
129 {
130 return $this->contexts;
131 }

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

Referenced by TestDefaultRenderer\_getContexts(), and ILIAS\UI\Implementation\DefaultRenderer\getRendererFor().

+ Here is the caller graph for this function:

◆ getJSCodeForAsyncRenderingFor()

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

Get JS-Code for asynchronous rendering of component.

Parameters
Component$component
Returns
string

Definition at line 104 of file DefaultRenderer.php.

105 {
106 return $this->component_renderer_loader
107 ->getRendererFactoryFor($component)
108 ->getJSBinding()
109 ->getOnLoadCodeAsync();
110 }

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

+ 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 93 of file DefaultRenderer.php.

93 : ComponentRenderer
94 {
95 return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
96 }
getContexts()
Get the contexts that are added via withAdditionalContext where most recently added contexts come las...

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

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

+ Here is the call graph for this function:
+ 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.

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 }
$out
Definition: buildRTE.php:24
getRendererFor(Component $component)
Get a renderer for a certain Component class.

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

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

+ 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 69 of file DefaultRenderer.php.

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 }
getJSCodeForAsyncRenderingFor(Component $component)
Get JS-Code for asynchronous rendering of component.
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...

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

+ Here is the call graph for this function:

◆ withAdditionalContext()

ILIAS\UI\Implementation\DefaultRenderer::withAdditionalContext ( Component  $context)

Get a new renderer with an additional context.A context makes it possible to use another renderer for (some) components when they are renderer as subcomponents of a certain components. The use case that spawned this functionality is the observation, that e.g. items representing repository objects are renderer in different lists, where the individual items look different every time but are morally the same item. Another use case could be a special rendering of input fields in filters over tables.If a component wants to render itself differently in different contexts, it must implement a RendererFactory. The class \ILIAS\UI\Implementation\Render\FSLoader contains directions how to do that.

Implements ILIAS\UI\Renderer.

Definition at line 115 of file DefaultRenderer.php.

115 : Renderer
116 {
117 $clone = clone $this;
118 $clone->contexts[] = $context;
119 return $clone;
120 }
An entity that renders components to a string output.
Definition: Renderer.php:31
$context
Definition: webdav.php:29

References $context.

Field Documentation

◆ $component_renderer_loader

Render Loader ILIAS\UI\Implementation\DefaultRenderer::$component_renderer_loader
private

◆ $contexts

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

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