ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
LoaderCachingWrapper.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
8
13{
14 use LoaderHelper;
15
19 private $loader;
20
24 private $cache = array();
25
26 public function __construct(Loader $loader)
27 {
28 $this->loader = $loader;
29 }
30
34 public function getRendererFor(Component $component, array $contexts)
35 {
36 $key = $this->getCacheKey($component, $contexts);
37 if (isset($this->cache[$key])) {
38 return $this->cache[$key];
39 }
40 $renderer = $this->loader->getRendererFor($component, $contexts);
41 $this->cache[$key] = $renderer;
42 return $renderer;
43 }
44
52 protected function getCacheKey(Component $component, array $contexts)
53 {
54 return $component->getCanonicalName() . " " . implode("_", $this->getContextNames($contexts));
55 }
56
60 public function getRendererFactoryFor(Component $component)
61 {
62 return $this->loader->getRendererFactoryFor($component);
63 }
64}
An exception for terminatinating execution or to throw for unit testing.
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.
$key
Definition: croninfo.php:18
A component is the most general form of an entity in the UI.
Definition: Component.php:14
getCanonicalName()
Get the canonical name of the component.
Loads renderers for components.
Definition: Loader.php:13