diff --git a/lib/Twig/Autoloader.php b/lib/Twig/Autoloader.php index 2bd3fcc13..2af5157e7 100644 --- a/lib/Twig/Autoloader.php +++ b/lib/Twig/Autoloader.php @@ -25,6 +25,8 @@ class Twig_Autoloader */ public static function register($prepend = false) { + @trigger_error('Using Twig_Autoloader is deprecated. Use Composer instead.', E_USER_DEPRECATED); + if (PHP_VERSION_ID < 50300) { spl_autoload_register(array(__CLASS__, 'autoload')); } else { diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index b7d470b1f..68517fdba 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -86,6 +86,8 @@ class Twig_Environment { if (null !== $loader) { $this->setLoader($loader); + } else { + @trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated.', E_USER_DEPRECATED); } $options = array_merge(array( @@ -448,6 +450,8 @@ class Twig_Environment */ public function clearTemplateCache() { + @trigger_error(sprintf('%s is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + $this->loadedTemplates = array(); } @@ -711,6 +715,8 @@ class Twig_Environment */ public function removeExtension($name) { + @trigger_error(sprintf('%s is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + if ($this->extensionInitialized) { throw new LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); } @@ -830,6 +836,8 @@ class Twig_Environment if ($name instanceof Twig_SimpleFilter) { $filter = $name; $name = $filter->getName(); + } else { + @trigger_error(sprintf('Passing a name as a first argument to %s is deprecated. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -919,6 +927,8 @@ class Twig_Environment if ($name instanceof Twig_SimpleTest) { $test = $name; $name = $test->getName(); + } else { + @trigger_error(sprintf('Passing a name as a first argument to %s is deprecated. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -977,6 +987,8 @@ class Twig_Environment if ($name instanceof Twig_SimpleFunction) { $function = $name; $name = $function->getName(); + } else { + @trigger_error(sprintf('Passing a name as a first argument to %s is deprecated. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1067,11 +1079,11 @@ class Twig_Environment $this->globals = $this->initGlobals(); } - /* This condition must be uncommented in Twig 2.0 if (!array_key_exists($name, $this->globals)) { - throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); + // The deprecation notice must be turned into the following exception in Twig 2.0 + @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated.', $name), E_USER_DEPRECATED); + //throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); } - */ } if ($this->extensionInitialized || $this->runtimeInitialized) { @@ -1206,6 +1218,8 @@ class Twig_Environment foreach ($extension->getFilters() as $name => $filter) { if ($filter instanceof Twig_SimpleFilter) { $name = $filter->getName(); + } else { + @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated. Use Twig_SimpleFilter instead.', get_class($filter), $name), E_USER_DEPRECATED); } $this->filters[$name] = $filter; @@ -1215,6 +1229,8 @@ class Twig_Environment foreach ($extension->getFunctions() as $name => $function) { if ($function instanceof Twig_SimpleFunction) { $name = $function->getName(); + } else { + @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated. Use Twig_SimpleFunction instead.', get_class($filter), $name), E_USER_DEPRECATED); } $this->functions[$name] = $function; @@ -1224,6 +1240,8 @@ class Twig_Environment foreach ($extension->getTests() as $name => $test) { if ($test instanceof Twig_SimpleTest) { $name = $test->getName(); + } else { + @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated. Use Twig_SimpleTest instead.', get_class($filter), $name), E_USER_DEPRECATED); } $this->tests[$name] = $test; @@ -1234,6 +1252,8 @@ class Twig_Environment if ($parser instanceof Twig_TokenParserInterface) { $this->parsers->addTokenParser($parser); } elseif ($parser instanceof Twig_TokenParserBrokerInterface) { + @trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated.', E_USER_DEPRECATED); + $this->parsers->addTokenParserBroker($parser); } else { throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances'); diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index cf2020eec..52983fb29 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -61,6 +61,8 @@ class Twig_Extension_Escaper extends Twig_Extension { // for BC if (true === $defaultStrategy) { + @trigger_error('Using "true" as the default strategy is deprecated. Use "html" instead.', E_USER_DEPRECATED); + $defaultStrategy = 'html'; } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 1c78e7b27..40d67fe59 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -74,6 +74,8 @@ class Twig_Node implements Twig_NodeInterface */ public function toXml($asDom = false) { + @trigger_error(sprintf('%s is deprecated.', __METHOD__), E_USER_DEPRECATED); + $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $dom->appendChild($xml = $dom->createElement('twig')); diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index a6e0ff420..c062a213f 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -30,11 +30,19 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression if ($this->getAttribute('is_defined_test')) { if ($this->isSpecial()) { + if ('_self' === $name) { + @trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED); + } + $compiler->repr(true); } else { $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)'); } } elseif ($this->isSpecial()) { + if ('_self' === $name) { + @trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED); + } + $compiler->raw($this->specialVars[$name]); } elseif ($this->getAttribute('always_defined')) { $compiler diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index 275602883..a8a3d7aa1 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -57,6 +57,8 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser } if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { + @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated.', E_USER_DEPRECATED); + if (false === $value) { throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename()); } diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index 905d8ee9b..e605e9a50 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -21,7 +21,6 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase public function getTests() { $node = new Twig_Node_Expression_Name('foo', 1); - $self = new Twig_Node_Expression_Name('_self', 1); $context = new Twig_Node_Expression_Name('_context', 1); $env = new Twig_Environment(null, array('strict_variables' => true)); @@ -30,7 +29,6 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase return array( array($node, "// line 1\n".(PHP_VERSION_ID >= 50400 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env), array($node, $this->getVariableGetter('foo', 1), $env1), - array($self, "// line 1\n\$this"), array($context, "// line 1\n\$context"), ); }