drop support for PHP 5.3 and 5.4

This commit is contained in:
Fabien Potencier
2014-11-13 09:05:27 +01:00
parent 176f60d79d
commit 706d659deb
11 changed files with 17 additions and 138 deletions
-2
View File
@@ -1,8 +1,6 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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" : {
+1 -1
View File
@@ -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
------------
+1 -6
View File
@@ -163,12 +163,7 @@ class Twig_Error extends Exception
$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']);
+10 -29
View File
@@ -43,37 +43,18 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
->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('))');
}
}
}
-35
View File
@@ -1,35 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2011 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_SetTemp extends Twig_Node
{
public function __construct($name, $lineno)
{
parent::__construct(array(), array('name' => $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")
;
}
}
+1 -42
View File
@@ -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 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
$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 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
$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;
}
+1 -5
View File
@@ -42,11 +42,7 @@ abstract class Twig_Test_NodeTestCase extends PHPUnit_Framework_TestCase
{
$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()
+1 -1
View File
@@ -28,7 +28,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase
$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"),
@@ -34,21 +34,6 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends PHPUnit_Framework_TestCase
$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
*/