PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.4
Elementor Website Builder – more than just a page builder v3.28.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / vendor_prefixed / twig / src / Loader / ArrayLoader.php

ArrayLoader.php in Elementor Website Builder – more than just a page builder 3.28.4, at vendor_prefixed/twig/src/Loader/ArrayLoader.php

67 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace ElementorDeps\Twig\Loader;
12
13 use ElementorDeps\Twig\Error\LoaderError;
14 use ElementorDeps\Twig\Source;
15 /**
16 * Loads a template from an array.
17 *
18 * When using this loader with a cache mechanism, you should know that a new cache
19 * key is generated each time a template content "changes" (the cache key being the
20 * source code of the template). If you don't want to see your cache grows out of
21 * control, you need to take care of clearing the old cache file by yourself.
22 *
23 * This loader should only be used for unit testing.
24 *
25 * @author Fabien Potencier <fabien@symfony.com>
26 */
27 final class ArrayLoader implements LoaderInterface
28 {
29 private $templates = [];
30 /**
31 * @param array $templates An array of templates (keys are the names, and values are the source code)
32 */
33 public function __construct(array $templates = [])
34 {
35 $this->templates = $templates;
36 }
37 public function setTemplate(string $name, string $template) : void
38 {
39 $this->templates[$name] = $template;
40 }
41 public function getSourceContext(string $name) : Source
42 {
43 if (!isset($this->templates[$name])) {
44 throw new LoaderError(\sprintf('Template "%s" is not defined.', $name));
45 }
46 return new Source($this->templates[$name], $name);
47 }
48 public function exists(string $name) : bool
49 {
50 return isset($this->templates[$name]);
51 }
52 public function getCacheKey(string $name) : string
53 {
54 if (!isset($this->templates[$name])) {
55 throw new LoaderError(\sprintf('Template "%s" is not defined.', $name));
56 }
57 return $name . ':' . $this->templates[$name];
58 }
59 public function isFresh(string $name, int $time) : bool
60 {
61 if (!isset($this->templates[$name])) {
62 throw new LoaderError(\sprintf('Template "%s" is not defined.', $name));
63 }
64 return \true;
65 }
66 }
67