diff --git a/.travis.yml b/.travis.yml index a8f69ab93c..69bb6303e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.3 - - 5.4 - 5.5 - 5.6 - hhvm diff --git a/CHANGELOG b/CHANGELOG index e9e96cc71f..eb6235398f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 2.0.0 (201X-XX-XX) - * dropped support for PHP 5.2 + * dropped support for PHP 5.2, 5.3, and 5.4 * removed the ability to register a global variable after the runtime or the extensions have been initialized * improved the performance of the filesystem loader * removed features that were deprecated in 1.x diff --git a/composer.json b/composer.json index 947a0eb2fe..16c356e3b7 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "forum": "https://groups.google.com/forum/#!forum/twig-users" }, "require": { - "php": ">=5.3.3" + "php": ">=5.5.0" }, "autoload": { "psr-0" : { diff --git a/doc/intro.rst b/doc/intro.rst index 52035bcd71..fee37e37f8 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -24,7 +24,7 @@ The key-features are... Prerequisites ------------- -Twig needs at least **PHP 5.3.3** to run. +Twig needs at least **PHP 5.5.0** to run. Installation ------------ diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 34b2ff9aeb..01e962c03d 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -163,12 +163,7 @@ protected function guessTemplateInfo() $template = null; $templateClass = null; - if (PHP_VERSION_ID >= 50306) { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); - } else { - $backtrace = debug_backtrace(); - } - + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); foreach ($backtrace as $trace) { if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) { $currentClass = get_class($trace['object']); diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 0bfcdbc459..9eebeff2f2 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -43,37 +43,18 @@ public function compile(Twig_Compiler $compiler) ->raw(']') ; } else { - // remove the non-PHP 5.4 version when PHP 5.3 support is dropped - // as the non-optimized version is just a workaround for slow ternary operator - // when the context has a lot of variables - if (PHP_VERSION_ID >= 50400) { - // PHP 5.4 ternary operator performance was optimized - $compiler - ->raw('(isset($context[') - ->string($name) - ->raw(']) ? $context[') - ->string($name) - ->raw('] : ') - ; + $compiler + ->raw('(isset($context[') + ->string($name) + ->raw(']) ? $context[') + ->string($name) + ->raw('] : ') + ; - if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { - $compiler->raw('null)'); - } else { - $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); - } + if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { + $compiler->raw('null)'); } else { - $compiler - ->raw('$this->getContext($context, ') - ->string($name) - ; - - if ($this->getAttribute('ignore_strict_check')) { - $compiler->raw(', true'); - } - - $compiler - ->raw(')') - ; + $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); } } } diff --git a/lib/Twig/Node/SetTemp.php b/lib/Twig/Node/SetTemp.php deleted file mode 100644 index 3bdd1cb74e..0000000000 --- a/lib/Twig/Node/SetTemp.php +++ /dev/null @@ -1,35 +0,0 @@ - $name), $lineno); - } - - public function compile(Twig_Compiler $compiler) - { - $name = $this->getAttribute('name'); - $compiler - ->addDebugInfo($this) - ->write('if (isset($context[') - ->string($name) - ->raw('])) { $_') - ->raw($name) - ->raw('_ = $context[') - ->repr($name) - ->raw(']; } else { $_') - ->raw($name) - ->raw("_ = null; }\n") - ; - } -} diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index c7d9217831..76fc6c79bb 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -25,13 +25,13 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface const OPTIMIZE_NONE = 0; const OPTIMIZE_FOR = 2; const OPTIMIZE_RAW_FILTER = 4; + // obsolete, does not do anything const OPTIMIZE_VAR_ACCESS = 8; protected $loops = array(); protected $loopsTargets = array(); protected $optimizers; protected $prependedNodes = array(); - protected $inABody = false; /** * Constructor. @@ -56,20 +56,6 @@ public function enterNode(Twig_Node $node, Twig_Environment $env) $this->enterOptimizeFor($node, $env); } - if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) { - if ($this->inABody) { - if (!$node instanceof Twig_Node_Expression) { - if (get_class($node) !== 'Twig_Node') { - array_unshift($this->prependedNodes, array()); - } - } else { - $node = $this->optimizeVariables($node, $env); - } - } elseif ($node instanceof Twig_Node_Body) { - $this->inABody = true; - } - } - return $node; } @@ -90,33 +76,6 @@ public function leaveNode(Twig_Node $node, Twig_Environment $env) $node = $this->optimizePrintNode($node, $env); - if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) { - if ($node instanceof Twig_Node_Body) { - $this->inABody = false; - } elseif ($this->inABody) { - if (!$expression && get_class($node) !== 'Twig_Node' && $prependedNodes = array_shift($this->prependedNodes)) { - $nodes = array(); - foreach (array_unique($prependedNodes) as $name) { - $nodes[] = new Twig_Node_SetTemp($name, $node->getLine()); - } - - $nodes[] = $node; - $node = new Twig_Node($nodes); - } - } - } - - return $node; - } - - protected function optimizeVariables(Twig_Node $node, Twig_Environment $env) - { - if ('Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) { - $this->prependedNodes[0][] = $node->getAttribute('name'); - - return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getLine()); - } - return $node; } diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php index bf865211bb..4f1ce6907a 100644 --- a/lib/Twig/Test/NodeTestCase.php +++ b/lib/Twig/Test/NodeTestCase.php @@ -42,11 +42,7 @@ protected function getVariableGetter($name, $line = false) { $line = $line > 0 ? "// line {$line}\n" : ''; - if (PHP_VERSION_ID >= 50400) { - return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); - } - - return sprintf('%s$this->getContext($context, "%s")', $line, $name); + return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); } protected function getAttributeGetter() diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index 905d8ee9b1..a4e28bdf4d 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -28,7 +28,7 @@ public function getTests() $env1 = new Twig_Environment(null, array('strict_variables' => false)); 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, "// line 1\n".'(isset($context["foo"]) ? $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"), diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 6b5792f862..aca8970cc8 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -34,21 +34,6 @@ public function testRenderParentBlockOptimizer() $this->assertTrue($node->getAttribute('output')); } - public function testRenderVariableBlockOptimizer() - { - if (PHP_VERSION_ID >= 50400) { - return; - } - - $env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false)); - $stream = $env->parse($env->tokenize('{{ block(name|lower) }}', 'index')); - - $node = $stream->getNode('body')->getNode(0)->getNode(1); - - $this->assertEquals('Twig_Node_Expression_BlockReference', get_class($node)); - $this->assertTrue($node->getAttribute('output')); - } - /** * @dataProvider getTestsForForOptimizer */