mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 13:26:37 +00:00
remove string casts from loader which was done for template reference objects, but this type of parameter is not contracted by the LoaderInterface
This commit is contained in:
committed by
Fabien Potencier
parent
5eff1b16ba
commit
558ca46b5e
@@ -45,7 +45,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function setTemplate($name, $template)
|
||||
{
|
||||
$this->templates[(string) $name] = $template;
|
||||
$this->templates[$name] = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function getSource($name)
|
||||
{
|
||||
$name = (string) $name;
|
||||
if (!isset($this->templates[$name])) {
|
||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
||||
}
|
||||
@@ -66,7 +65,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function exists($name)
|
||||
{
|
||||
return isset($this->templates[(string) $name]);
|
||||
return isset($this->templates[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +73,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function getCacheKey($name)
|
||||
{
|
||||
$name = (string) $name;
|
||||
if (!isset($this->templates[$name])) {
|
||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
||||
}
|
||||
@@ -87,7 +85,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function isFresh($name, $time)
|
||||
{
|
||||
$name = (string) $name;
|
||||
if (!isset($this->templates[$name])) {
|
||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
@@ -68,8 +68,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function exists($name)
|
||||
{
|
||||
$name = (string) $name;
|
||||
|
||||
if (isset($this->hasSourceCache[$name])) {
|
||||
return $this->hasSourceCache[$name];
|
||||
}
|
||||
|
||||
@@ -212,6 +212,11 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
{
|
||||
return preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
|
||||
}
|
||||
|
||||
protected function parseName($name, $default = self::MAIN_NAMESPACE)
|
||||
{
|
||||
if (isset($name[0]) && '@' == $name[0]) {
|
||||
@@ -228,11 +233,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
return array($default, $name);
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
{
|
||||
return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/'));
|
||||
}
|
||||
|
||||
protected function validateName($name)
|
||||
{
|
||||
if (false !== strpos($name, "\0")) {
|
||||
|
||||
@@ -68,30 +68,4 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$loader->isFresh('foo', time());
|
||||
}
|
||||
|
||||
public function testTemplateReference()
|
||||
{
|
||||
$name = new Twig_Test_Loader_TemplateReference('foo');
|
||||
$loader = new Twig_Loader_Array(array('foo' => 'bar'));
|
||||
|
||||
$loader->getCacheKey($name);
|
||||
$loader->getSource($name);
|
||||
$loader->isFresh($name, time());
|
||||
$loader->setTemplate($name, 'foobar');
|
||||
}
|
||||
}
|
||||
|
||||
class Twig_Test_Loader_TemplateReference
|
||||
{
|
||||
private $name;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user