mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 03:16:34 +00:00
deprecated the possibility to override an extension by registering another one with the same name
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.23.0 (2015-XX-XX)
|
||||
|
||||
* deprecated the possibility to override an extension by registering another one with the same name
|
||||
* deprecated Twig_ExtensionInterface::initRuntime() (added Twig_Extension_InitRuntimeInterface for BC)
|
||||
* deprecated Twig_Environment::computeAlternatives()
|
||||
|
||||
|
||||
@@ -780,13 +780,19 @@ class Twig_Environment
|
||||
*/
|
||||
public function addExtension(Twig_ExtensionInterface $extension)
|
||||
{
|
||||
$name = $extension->getName();
|
||||
|
||||
if ($this->extensionInitialized) {
|
||||
throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName()));
|
||||
throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $name));
|
||||
}
|
||||
|
||||
if (isset($this->extensions[$name])) {
|
||||
@trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $name), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->lastModifiedExtension = 0;
|
||||
|
||||
$this->extensions[$extension->getName()] = $extension;
|
||||
$this->extensions[$name] = $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -342,6 +342,26 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.3
|
||||
*/
|
||||
public function testOverrideExtenion()
|
||||
{
|
||||
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
|
||||
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
|
||||
|
||||
$this->deprecations = array();
|
||||
set_error_handler(array($this, 'handleError'));
|
||||
|
||||
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
|
||||
$twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
|
||||
|
||||
$this->assertCount(1, $this->deprecations);
|
||||
$this->assertContains('The possibility to register the same extension twice', $this->deprecations[0]);
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
protected function getMockLoader($templateName, $templateContent)
|
||||
{
|
||||
$loader = $this->getMock('Twig_LoaderInterface');
|
||||
|
||||
Reference in New Issue
Block a user