feature #2968 Various removals (fabpot)

This PR was squashed before being merged into the 3.x branch (closes #2968).

Discussion
----------

Various removals

Each commit is a "simple" removal of an obsolete feature.

Commits
-------

802646aa removed Template::__toString()
02767df5 removed block definition nested in non-capturing nodes
2fa26d6f removed Parser::isReservedMacroName()
12972d00 removed obsolete OPTIMIZE_VAR_ACCESS const
5b1aad86 removed remaining code supporting PSR-0 class names
7fb5fb44 simplified code
85fc1eff removed the possibility to pass a Template to Environment::load()
This commit is contained in:
Fabien Potencier
2019-04-23 18:33:21 +02:00
8 changed files with 8 additions and 55 deletions
-6
View File
@@ -314,12 +314,6 @@ class Environment
return $name;
}
if ($name instanceof Template) {
@trigger_error('Passing a \Twig\Template instance to '.__METHOD__.' is deprecated since Twig 2.7.0, use \Twig\TemplateWrapper instead.', E_USER_DEPRECATED);
return new TemplateWrapper($this, $name);
}
return new TemplateWrapper($this, $this->loadTemplate($this->getTemplateClass($name), $name));
}
+1 -4
View File
@@ -196,10 +196,7 @@ class ExpressionParser
$class = $this->unaryOperators[$token->getValue()]['class'];
$ref = new \ReflectionClass($class);
if (!(\in_array($ref->getName(), [NegUnary::class, PosUnary::class, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos'])
|| $ref->isSubclassOf(NegUnary::class) || $ref->isSubclassOf(PosUnary::class)
|| $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos'))
) {
if (!\in_array($class, [NegUnary::class, PosUnary::class])) {
throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
}
+1 -13
View File
@@ -69,22 +69,12 @@ final class ExtensionSet
public function hasExtension(string $class): bool
{
$class = ltrim($class, '\\');
if (!isset($this->extensions[$class]) && class_exists($class, false)) {
// For BC/FC with namespaced aliases
$class = (new \ReflectionClass($class))->name;
}
return isset($this->extensions[$class]);
return isset($this->extensions[ltrim($class, '\\')]);
}
public function getExtension(string $class): ExtensionInterface
{
$class = ltrim($class, '\\');
if (!isset($this->extensions[$class]) && class_exists($class, false)) {
// For BC/FC with namespaced aliases
$class = (new \ReflectionClass($class))->name;
}
if (!isset($this->extensions[$class])) {
throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class));
@@ -149,8 +139,6 @@ final class ExtensionSet
throw new \LogicException(sprintf('Unable to register extension "%s" as it is already registered.', $class));
}
// For BC/FC with namespaced aliases
$class = (new \ReflectionClass($class))->name;
$this->extensions[$class] = $extension;
}
+1 -2
View File
@@ -37,8 +37,7 @@ abstract class CallExpression extends AbstractExpression
$compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
}
} elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) {
// For BC/FC with namespaced aliases
$class = (new \ReflectionClass(\get_class($callable[0])))->name;
$class = \get_class($callable[0]);
if (!$compiler->getEnvironment()->hasExtension($class)) {
// Compile a non-optimized call to trigger a \Twig\Error\RuntimeError, which cannot be a compile-time error
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')', $class));
+1 -3
View File
@@ -41,8 +41,6 @@ final class OptimizerNodeVisitor extends AbstractNodeVisitor
const OPTIMIZE_NONE = 0;
const OPTIMIZE_FOR = 2;
const OPTIMIZE_RAW_FILTER = 4;
// obsolete, does not do anything
const OPTIMIZE_VAR_ACCESS = 8;
private $loops = [];
private $loopsTargets = [];
@@ -53,7 +51,7 @@ final class OptimizerNodeVisitor extends AbstractNodeVisitor
*/
public function __construct(int $optimizers = -1)
{
if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) {
if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER)) {
throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers));
}
+2 -15
View File
@@ -244,16 +244,6 @@ class Parser
$this->macros[$name] = $node;
}
/**
* @deprecated since Twig 2.7 as there are no reserved macro names anymore, will be removed in 3.0.
*/
public function isReservedMacroName($name)
{
@trigger_error(sprintf('The "%s" method is deprecated since Twig 2.7 and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
return false;
}
public function addTrait($trait)
{
$this->traits[] = $trait;
@@ -362,11 +352,8 @@ class Parser
// "block" tags that are not captured (see above) are only used for defining
// the content of the block. In such a case, nesting it does not work as
// expected as the definition is not part of the default template code flow.
if ($nested && ($node instanceof BlockReferenceNode || $node instanceof \Twig_Node_BlockReference)) {
//throw new SyntaxError('A block definition cannot be nested under non-capturing nodes.', $node->getTemplateLine(), $this->stream->getSourceContext());
@trigger_error(sprintf('Nesting a block definition under a non-capturing node in "%s" at line %d is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.', $this->stream->getSourceContext()->getName(), $node->getTemplateLine()), E_USER_DEPRECATED);
return;
if ($nested && $node instanceof BlockReferenceNode) {
throw new SyntaxError('A block definition cannot be nested under non-capturing nodes.', $node->getTemplateLine(), $this->stream->getSourceContext());
}
if ($node instanceof NodeOutputInterface) {
-8
View File
@@ -47,14 +47,6 @@ abstract class Template
$this->extensions = $env->getExtensions();
}
/**
* @internal this method will be removed in 3.0 and is only used internally to provide an upgrade path from 1.x to 2.0
*/
public function __toString()
{
return $this->getTemplateName();
}
/**
* Returns the template name.
*
@@ -1,7 +1,5 @@
--TEST--
conditional "block" tag with "extends" tag
--DEPRECATION--
Nesting a block definition under a non-capturing node in "index.twig" at line 5 is deprecated since Twig 2.5.0 and will become a syntax error in 3.0.
--TEMPLATE--
{% extends "layout.twig" %}
@@ -12,5 +10,5 @@ Nesting a block definition under a non-capturing node in "index.twig" at line 5
{% block content %}{% endblock %}
--DATA--
return array()
--EXPECT--
FOO
--EXCEPTION--
Twig\Error\SyntaxError: A block definition cannot be nested under non-capturing nodes in "index.twig" at line 5.