ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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, private \ILIAS\Language\Language $language,)
 
 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...
 
 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...
 

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,
private \ILIAS\Language\Language  $language 
)

Definition at line 40 of file DefaultRenderer.php.

44 {
45 }

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

112 : array
113 {
114 return $this->contexts;
115 }

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

Referenced by TestDefaultRenderer\_getContexts(), and 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.

Exceptions
LogicExceptionif no renderer could be found for component.

Definition at line 101 of file DefaultRenderer.php.

101 : ComponentRenderer
102 {
103 return $this->component_renderer_loader->getRendererFor($component, $this->getContexts());
104 }
getContexts()
Returns the current context stack, where most recently added components are last.

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:

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

129 : void
130 {
131 array_pop($this->contexts);
132 }

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

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

120 : void
121 {
122 $this->contexts[] = $component;
123 }

Referenced by TestDefaultRenderer\__construct(), and ILIAS\UI\Implementation\DefaultRenderer\render().

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

51 {
52 $this->language->loadLanguageModule('ui');
53
54 $root = $root ?? $this;
55
56 $out = '';
57 if (is_array($component)) {
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 }
$out
Definition: buildRTE.php:24
$renderer
pushContext(Component $component)
Adds a component to the current context stack.
popContext()
Removes the most recently added component from the current context stack.
getRendererFor(Component $component)
Get a renderer for a certain Component class.

References $out, $renderer, ILIAS\UI\Implementation\DefaultRenderer\getRendererFor(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\UI\Implementation\DefaultRenderer\popContext(), and ILIAS\UI\Implementation\DefaultRenderer\pushContext().

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

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

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

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