summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Loader/Array.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/lib/Twig/Loader/Array.php')
-rw-r--r--inc/lib/Twig/Loader/Array.php42
1 files changed, 22 insertions, 20 deletions
diff --git a/inc/lib/Twig/Loader/Array.php b/inc/lib/Twig/Loader/Array.php
index ac561048..0aac7690 100644
--- a/inc/lib/Twig/Loader/Array.php
+++ b/inc/lib/Twig/Loader/Array.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2009 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -17,20 +17,20 @@
* source code of the template). If you don't want to see your cache grows out of
* control, you need to take care of clearing the old cache file by yourself.
*
+ * This loader should only be used for unit testing.
+ *
+ * @final
+ *
* @author Fabien Potencier <fabien@symfony.com>
*/
-class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
+class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
{
protected $templates = array();
/**
- * Constructor.
- *
* @param array $templates An array of templates (keys are the names, and values are the source code)
- *
- * @see Twig_Loader
*/
- public function __construct(array $templates)
+ public function __construct(array $templates = array())
{
$this->templates = $templates;
}
@@ -46,11 +46,10 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
$this->templates[(string) $name] = $template;
}
- /**
- * {@inheritdoc}
- */
public function getSource($name)
{
+ @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
+
$name = (string) $name;
if (!isset($this->templates[$name])) {
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
@@ -59,17 +58,21 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
return $this->templates[$name];
}
- /**
- * {@inheritdoc}
- */
+ public function getSourceContext($name)
+ {
+ $name = (string) $name;
+ if (!isset($this->templates[$name])) {
+ throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
+ }
+
+ return new Twig_Source($this->templates[$name], $name);
+ }
+
public function exists($name)
{
return isset($this->templates[(string) $name]);
}
- /**
- * {@inheritdoc}
- */
public function getCacheKey($name)
{
$name = (string) $name;
@@ -77,12 +80,9 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
}
- return $this->templates[$name];
+ return $name.':'.$this->templates[$name];
}
- /**
- * {@inheritdoc}
- */
public function isFresh($name, $time)
{
$name = (string) $name;
@@ -93,3 +93,5 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
return true;
}
}
+
+class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false);