Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Template / Loader / StringLoader.php
1 <?php
2
3 namespace Drupal\Core\Template\Loader;
4
5 /**
6  * Loads string templates, also known as inline templates.
7  *
8  * This loader is intended to be used in a Twig loader chain and whitelists
9  * string templates that begin with the following comment:
10  * @code
11  * {# inline_template_start #}
12  * @endcode
13  *
14  * This class override ensures that the string loader behaves as expected in
15  * the loader chain. If Twig's string loader is used as is, any string (even a
16  * reference to a file-based Twig template) is treated as a valid template and
17  * is rendered instead of a \Twig_Error_Loader exception being thrown.
18  *
19  * @see \Drupal\Core\Template\TwigEnvironment::renderInline()
20  * @see \Drupal\Core\Render\Element\InlineTemplate
21  * @see twig_render_template()
22  */
23 class StringLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface {
24
25   /**
26    * {@inheritdoc}
27    */
28   public function exists($name) {
29     if (strpos($name, '{# inline_template_start #}') === 0) {
30       return TRUE;
31     }
32     else {
33       return FALSE;
34     }
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function getSource($name) {
41     return $name;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getCacheKey($name) {
48     return $name;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function isFresh($name, $time) {
55     return TRUE;
56   }
57
58 }