ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LoaderCachingWrapper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 use LoaderHelper;
31
32 private Loader $loader;
33
37 private array $cache = array();
38
39 public function __construct(Loader $loader)
40 {
41 $this->loader = $loader;
42 }
43
47 public function getRendererFor(Component $component, array $contexts): ComponentRenderer
48 {
49 $key = $this->getCacheKey($component, $contexts);
50 if (isset($this->cache[$key])) {
51 return $this->cache[$key];
52 }
53 $renderer = $this->loader->getRendererFor($component, $contexts);
54 $this->cache[$key] = $renderer;
55 return $renderer;
56 }
57
63 protected function getCacheKey(Component $component, array $contexts): string
64 {
65 return $component->getCanonicalName() . " " . implode("_", $this->getContextNames($contexts));
66 }
67
71 public function getRendererFactoryFor(Component $component): RendererFactory
72 {
73 return $this->loader->getRendererFactoryFor($component);
74 }
75}
$renderer
Caches renderers loaded by another loader.
getRendererFactoryFor(Component $component)
@inheritdocs
getRendererFor(Component $component, array $contexts)
@inheritdocs
getCacheKey(Component $component, array $contexts)
Get a key for the cache.
A component is the most general form of an entity in the UI.
Definition: Component.php:28
getCanonicalName()
Get the canonical name of the component.
An entity that renders components to a string output.
Loads renderers for components.
Definition: Loader.php:30
This is the interface that components should use if they want to load specific renderers.