ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 renderered. 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)
 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
Returns
string
More...
 
 renderAsync ($component)
 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
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 contains directions how to do that.
Parameters
Component$context
Returns
Renderer
More...
 

Protected Member Functions

 getRendererFor (Component $component)
 Get a renderer for a certain Component class. More...
 
 getContexts ()
 Get the contexts that are added via withAdditionalContext where most recently added contexts come last. More...
 

Private Attributes

 $component_renderer_loader
 
 $contexts = []
 

Detailed Description

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

Definition at line 15 of file DefaultRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 27 of file DefaultRenderer.php.

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

28  {
29  $this->component_renderer_loader = $component_renderer_loader;
30  }

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

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

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

+ 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.

Parameters
Component$component
Exceptions

Definition at line 86 of file DefaultRenderer.php.

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

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

87  {
88  return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
89  }
getContexts()
Get the contexts that are added via withAdditionalContext where most recently added contexts come las...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ILIAS\UI\Implementation\DefaultRenderer::render (   $component)

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
Returns
string

Implements ILIAS\UI\Renderer.

Definition at line 35 of file DefaultRenderer.php.

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

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

36  {
37  $out = '';
38  if (is_array($component)) {
39  foreach ($component as $_component) {
40  $renderer = $this->getRendererFor($_component);
41  $out .= $renderer->render($_component, $this);
42  }
43  } else {
44  $renderer = $this->getRendererFor($component);
45  $out = $renderer->render($component, $this);
46  }
47 
48  return $out;
49  }
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)

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
Returns
string

Implements ILIAS\UI\Renderer.

Definition at line 54 of file DefaultRenderer.php.

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

55  {
56  $out = '';
57 
58  if (is_array($component)) {
59  foreach ($component as $_component) {
60  $out .= $this->render($_component) .
61  $this->component_renderer_loader
62  ->getRendererFactoryFor($_component)
63  ->getJSBinding()
64  ->getOnLoadCodeAsync();
65  }
66  } else {
67  $out = $this->render($component) .
68  $this->component_renderer_loader
69  ->getRendererFactoryFor($component)
70  ->getJSBinding()
71  ->getOnLoadCodeAsync();
72  }
73  return $out;
74  }
render($component)
Render given component.If an array of components is passed, this method returns a concatenated output...
+ 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 contains directions how to do that.

Parameters
Component$context
Returns
Renderer

Implements ILIAS\UI\Renderer.

Definition at line 94 of file DefaultRenderer.php.

95  {
96  $clone = clone $this;
97  $clone->contexts[] = $context;
98  return $clone;
99  }

Field Documentation

◆ $component_renderer_loader

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

◆ $contexts

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

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