mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 03:16:34 +00:00
removed obsolete code
This commit is contained in:
@@ -530,10 +530,6 @@ class Twig_Environment
|
||||
*/
|
||||
public function setLoader(Twig_LoaderInterface $loader)
|
||||
{
|
||||
if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(get_class($loader), 'Mock_Twig_LoaderInterface')) {
|
||||
@trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', get_class($loader)), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->loader = $loader;
|
||||
}
|
||||
|
||||
@@ -554,12 +550,7 @@ class Twig_Environment
|
||||
*/
|
||||
public function getSourceContext($name)
|
||||
{
|
||||
$loader = $this->getLoader();
|
||||
if (!$loader instanceof Twig_SourceContextLoaderInterface) {
|
||||
return new Twig_Source($loader->getSource($name), $name);
|
||||
}
|
||||
|
||||
return $loader->getSourceContext($name);
|
||||
return $this->getLoader()->getSourceContext($name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,20 +46,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
$this->templates[$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);
|
||||
|
||||
if (!isset($this->templates[$name])) {
|
||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return $this->templates[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -42,27 +42,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
$this->hasSourceCache = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSource($name)
|
||||
{
|
||||
$exceptions = array();
|
||||
foreach ($this->loaders as $loader) {
|
||||
if (!$loader->exists($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
return $loader->getSource($name);
|
||||
} catch (Twig_Error_Loader $e) {
|
||||
$exceptions[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -75,11 +54,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
}
|
||||
|
||||
try {
|
||||
if ($loader instanceof Twig_SourceContextLoaderInterface) {
|
||||
return $loader->getSourceContext($name);
|
||||
}
|
||||
|
||||
return new Twig_Source($loader->getSource($name), $name);
|
||||
return $loader->getSourceContext($name);
|
||||
} catch (Twig_Error_Loader $e) {
|
||||
$exceptions[] = $e->getMessage();
|
||||
}
|
||||
|
||||
@@ -133,16 +133,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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);
|
||||
|
||||
return file_get_contents($this->findTemplate($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
interface Twig_LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Gets the source code of a template, given its name.
|
||||
* Returns the source context for a given template logical name.
|
||||
*
|
||||
* @param string $name The name of the template to load
|
||||
* @param string $name The template logical name
|
||||
*
|
||||
* @return string The template source code
|
||||
* @return Twig_Source
|
||||
*
|
||||
* @throws Twig_Error_Loader When $name is not found
|
||||
*
|
||||
* @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface
|
||||
*/
|
||||
public function getSource($name);
|
||||
public function getSourceContext($name);
|
||||
|
||||
/**
|
||||
* Gets the cache key to use for the cache for a given template name.
|
||||
|
||||
@@ -10,22 +10,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds a getSourceContext() method for loaders.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since 1.27 (to be removed in 3.0)
|
||||
* Empty interface for Twig 1.x compatibility.
|
||||
*/
|
||||
interface Twig_SourceContextLoaderInterface
|
||||
interface Twig_SourceContextLoaderInterface extends Twig_LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Returns the source context for a given template logical name.
|
||||
*
|
||||
* @param string $name The template logical name
|
||||
*
|
||||
* @return Twig_Source
|
||||
*
|
||||
* @throws Twig_Error_Loader When $name is not found
|
||||
*/
|
||||
public function getSourceContext($name);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Twig_TokenStream
|
||||
public function __construct(array $tokens, Twig_Source $source = null)
|
||||
{
|
||||
$this->tokens = $tokens;
|
||||
$this->source = $source ?: new Twig_Source('');
|
||||
$this->source = $source ?: new Twig_Source('', '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -286,7 +286,9 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation()
|
||||
{
|
||||
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
||||
$loader = $this->getMockBuilder('Twig_LoaderInterface')->getMock();
|
||||
$twig = new Twig_Environment($loader);
|
||||
$loader->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', '')));
|
||||
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime());
|
||||
|
||||
$twig->loadTemplate('');
|
||||
|
||||
@@ -11,27 +11,6 @@
|
||||
|
||||
class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetSource()
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array('foo' => 'bar'));
|
||||
|
||||
$this->assertEquals('bar', $loader->getSource('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException Twig_Error_Loader
|
||||
*/
|
||||
public function testGetSourceWhenTemplateDoesNotExist()
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array());
|
||||
|
||||
$loader->getSource('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Twig_Error_Loader
|
||||
*/
|
||||
|
||||
@@ -11,20 +11,6 @@
|
||||
|
||||
class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetSource()
|
||||
{
|
||||
$loader = new Twig_Loader_Chain(array(
|
||||
new Twig_Loader_Array(array('foo' => 'bar')),
|
||||
new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
|
||||
));
|
||||
|
||||
$this->assertEquals('bar', $loader->getSource('foo'));
|
||||
$this->assertEquals('foo', $loader->getSource('bar'));
|
||||
}
|
||||
|
||||
public function testGetSourceContext()
|
||||
{
|
||||
$path = dirname(__FILE__).'/../Fixtures';
|
||||
@@ -56,17 +42,6 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
|
||||
$loader->getSourceContext('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException Twig_Error_Loader
|
||||
*/
|
||||
public function testGetSourceWhenTemplateDoesNotExist()
|
||||
{
|
||||
$loader = new Twig_Loader_Chain(array());
|
||||
|
||||
$loader->getSource('foo');
|
||||
}
|
||||
|
||||
public function testGetCacheKey()
|
||||
{
|
||||
$loader = new Twig_Loader_Chain(array(
|
||||
|
||||
Reference in New Issue
Block a user