mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 13:26:37 +00:00
dropped support for PHP 5.2
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.2
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
* 2.0.0 (201X-XX-XX)
|
||||
|
||||
* dropped support for PHP 5.2
|
||||
* 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
@@ -27,7 +27,7 @@
|
||||
"forum": "https://groups.google.com/forum/#!forum/twig-users"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.7"
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0" : {
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ The key-features are...
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
Twig needs at least **PHP 5.2.4** to run.
|
||||
Twig needs at least **PHP 5.3.3** to run.
|
||||
|
||||
Installation
|
||||
------------
|
||||
@@ -33,7 +33,7 @@ The recommended way to install Twig is via Composer:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
composer require "twig/twig:~1.0"
|
||||
composer require "twig/twig:~2.0"
|
||||
|
||||
.. note::
|
||||
|
||||
|
||||
@@ -23,11 +23,7 @@ class Twig_Autoloader
|
||||
*/
|
||||
public static function register($prepend = false)
|
||||
{
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'));
|
||||
} else {
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||
}
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-27
@@ -36,7 +36,6 @@ class Twig_Error extends Exception
|
||||
protected $lineno;
|
||||
protected $filename;
|
||||
protected $rawMessage;
|
||||
protected $previous;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -57,12 +56,7 @@ class Twig_Error extends Exception
|
||||
*/
|
||||
public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null)
|
||||
{
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
$this->previous = $previous;
|
||||
parent::__construct('');
|
||||
} else {
|
||||
parent::__construct('', 0, $previous);
|
||||
}
|
||||
parent::__construct('', 0, $previous);
|
||||
|
||||
$this->lineno = $lineno;
|
||||
$this->filename = $filename;
|
||||
@@ -136,25 +130,6 @@ class Twig_Error extends Exception
|
||||
$this->updateRepr();
|
||||
}
|
||||
|
||||
/**
|
||||
* For PHP < 5.3.0, provides access to the getPrevious() method.
|
||||
*
|
||||
* @param string $method The method name
|
||||
* @param array $arguments The parameters to be passed to the method
|
||||
*
|
||||
* @return Exception The previous exception or null
|
||||
*
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if ('getprevious' == strtolower($method)) {
|
||||
return $this->previous;
|
||||
}
|
||||
|
||||
throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
|
||||
}
|
||||
|
||||
protected function updateRepr()
|
||||
{
|
||||
$this->message = $this->rawMessage;
|
||||
@@ -223,7 +198,7 @@ class Twig_Error extends Exception
|
||||
}
|
||||
|
||||
$exceptions = array($e = $this);
|
||||
while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) {
|
||||
while ($e = $e->getPrevious()) {
|
||||
$exceptions[] = $e;
|
||||
}
|
||||
|
||||
|
||||
+15
-40
@@ -604,44 +604,23 @@ function twig_urlencode_filter($url)
|
||||
return rawurlencode($url);
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
/**
|
||||
* JSON encodes a variable.
|
||||
*
|
||||
* @param mixed $value The value to encode.
|
||||
* @param int $options Not used on PHP 5.2.x
|
||||
*
|
||||
* @return mixed The JSON encoded value
|
||||
*/
|
||||
function twig_jsonencode_filter($value, $options = 0)
|
||||
{
|
||||
if ($value instanceof Twig_Markup) {
|
||||
$value = (string) $value;
|
||||
} elseif (is_array($value)) {
|
||||
array_walk_recursive($value, '_twig_markup2string');
|
||||
}
|
||||
|
||||
return json_encode($value);
|
||||
/**
|
||||
* JSON encodes a variable.
|
||||
*
|
||||
* @param mixed $value The value to encode.
|
||||
* @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT
|
||||
*
|
||||
* @return mixed The JSON encoded value
|
||||
*/
|
||||
function twig_jsonencode_filter($value, $options = 0)
|
||||
{
|
||||
if ($value instanceof Twig_Markup) {
|
||||
$value = (string) $value;
|
||||
} elseif (is_array($value)) {
|
||||
array_walk_recursive($value, '_twig_markup2string');
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* JSON encodes a variable.
|
||||
*
|
||||
* @param mixed $value The value to encode.
|
||||
* @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT
|
||||
*
|
||||
* @return mixed The JSON encoded value
|
||||
*/
|
||||
function twig_jsonencode_filter($value, $options = 0)
|
||||
{
|
||||
if ($value instanceof Twig_Markup) {
|
||||
$value = (string) $value;
|
||||
} elseif (is_array($value)) {
|
||||
array_walk_recursive($value, '_twig_markup2string');
|
||||
}
|
||||
|
||||
return json_encode($value, $options);
|
||||
}
|
||||
return json_encode($value, $options);
|
||||
}
|
||||
|
||||
function _twig_markup2string(&$value)
|
||||
@@ -1060,10 +1039,6 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
|
||||
return $string;
|
||||
|
||||
case 'url':
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
return str_replace('%7E', '~', rawurlencode($string));
|
||||
}
|
||||
|
||||
return rawurlencode($string);
|
||||
|
||||
default:
|
||||
|
||||
@@ -39,8 +39,7 @@ class Twig_Node_For extends Twig_Node
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
// the (array) cast bypasses a PHP 5.2.6 bug
|
||||
->write("\$context['_parent'] = (array) \$context;\n")
|
||||
->write("\$context['_parent'] = \$context;\n")
|
||||
->write("\$context['_seq'] = twig_ensure_traversable(")
|
||||
->subcompile($this->getNode('seq'))
|
||||
->raw(");\n")
|
||||
|
||||
@@ -29,7 +29,7 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk()
|
||||
{
|
||||
$loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors');
|
||||
$loader = new Twig_Loader_Filesystem(__DIR__.'/Fixtures/errors');
|
||||
$twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
|
||||
|
||||
$template = $twig->loadTemplate('index.html');
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
--TEST--
|
||||
"date" filter (interval support as of PHP 5.3)
|
||||
--CONDITION--
|
||||
version_compare(phpversion(), '5.3.0', '>=')
|
||||
"date" filter (interval support)
|
||||
--TEMPLATE--
|
||||
{{ date2|date }}
|
||||
{{ date2|date('%d days') }}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
--TEST--
|
||||
"date" filter (interval support as of PHP 5.3)
|
||||
--CONDITION--
|
||||
version_compare(phpversion(), '5.3.0', '>=')
|
||||
"date" filter (interval support)
|
||||
--TEMPLATE--
|
||||
{{ date1|date }}
|
||||
{{ date1|date('%d days %h hours') }}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
--TEST--
|
||||
Twig is able to deal with SimpleXMLElement instances as variables
|
||||
--CONDITION--
|
||||
version_compare(phpversion(), '5.3.0', '>=')
|
||||
--TEMPLATE--
|
||||
Hello '{{ images.image.0.group }}'!
|
||||
{{ images.image.0.group.attributes.myattr }}
|
||||
|
||||
@@ -32,7 +32,7 @@ class Twig_Tests_IntegrationTest extends Twig_Test_IntegrationTestCase
|
||||
|
||||
public function getFixturesDir()
|
||||
{
|
||||
return dirname(__FILE__).'/Fixtures/';
|
||||
return __DIR__.'/Fixtures/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSecurity($template)
|
||||
{
|
||||
$loader = new Twig_Loader_Filesystem(array(dirname(__FILE__).'/../Fixtures'));
|
||||
$loader = new Twig_Loader_Filesystem(array(__DIR__.'/../Fixtures'));
|
||||
|
||||
try {
|
||||
$loader->getCacheKey($template);
|
||||
@@ -53,7 +53,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testPaths()
|
||||
{
|
||||
$basePath = dirname(__FILE__).'/Fixtures';
|
||||
$basePath = __DIR__.'/Fixtures';
|
||||
|
||||
$loader = new Twig_Loader_Filesystem(array($basePath.'/normal', $basePath.'/normal_bis'));
|
||||
$loader->setPaths(array($basePath.'/named', $basePath.'/named_bis'), 'named');
|
||||
@@ -103,7 +103,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFindTemplateExceptionNamespace()
|
||||
{
|
||||
$basePath = dirname(__FILE__).'/Fixtures';
|
||||
$basePath = __DIR__.'/Fixtures';
|
||||
|
||||
$loader = new Twig_Loader_Filesystem(array($basePath.'/normal'));
|
||||
$loader->addPath($basePath.'/named', 'named');
|
||||
@@ -118,7 +118,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFindTemplateWithCache()
|
||||
{
|
||||
$basePath = dirname(__FILE__).'/Fixtures';
|
||||
$basePath = __DIR__.'/Fixtures';
|
||||
|
||||
$loader = new Twig_Loader_Filesystem(array($basePath.'/normal'));
|
||||
$loader->addPath($basePath.'/named', 'named');
|
||||
@@ -134,9 +134,9 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
public function testLoadTemplateAndRenderBlockWithCache()
|
||||
{
|
||||
$loader = new Twig_Loader_Filesystem(array());
|
||||
$loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme2');
|
||||
$loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1');
|
||||
$loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1', 'default_theme');
|
||||
$loader->addPath(__DIR__.'/Fixtures/themes/theme2');
|
||||
$loader->addPath(__DIR__.'/Fixtures/themes/theme1');
|
||||
$loader->addPath(__DIR__.'/Fixtures/themes/theme1', 'default_theme');
|
||||
|
||||
$twig = new Twig_Environment($loader);
|
||||
|
||||
|
||||
@@ -64,10 +64,8 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
|
||||
$tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)');
|
||||
|
||||
// filter as an anonymous function
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))');
|
||||
}
|
||||
$node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
@@ -112,10 +110,9 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
return include 'PHP53/FilterInclude.php';
|
||||
}
|
||||
$env = new Twig_Environment();
|
||||
$env->addFilter(new Twig_SimpleFilter('anonymous', function () {}));
|
||||
|
||||
return parent::getEnvironment();
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,8 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
|
||||
$tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")');
|
||||
|
||||
// function as an anonymous function
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))');
|
||||
}
|
||||
$node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
@@ -78,10 +76,9 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
return include 'PHP53/FunctionInclude.php';
|
||||
}
|
||||
$env = new Twig_Environment();
|
||||
$env->addFunction(new Twig_SimpleFunction('anonymous', function () {}));
|
||||
|
||||
return parent::getEnvironment();
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
$env = new Twig_Environment();
|
||||
$env->addFilter(new Twig_SimpleFilter('anonymous', function () {}));
|
||||
|
||||
return $env;
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
$env = new Twig_Environment();
|
||||
$env->addFunction(new Twig_SimpleFunction('anonymous', function () {}));
|
||||
|
||||
return $env;
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
$env = new Twig_Environment();
|
||||
$env->addTest(new Twig_SimpleTest('anonymous', function () {}));
|
||||
|
||||
return $env;
|
||||
@@ -32,10 +32,8 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
|
||||
$tests[] = array($node, '(null === "foo")');
|
||||
|
||||
// test as an anonymous function
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))');
|
||||
}
|
||||
$node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
@@ -47,10 +45,9 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
return include 'PHP53/TestInclude.php';
|
||||
}
|
||||
$env = new Twig_Environment();
|
||||
$env->addTest(new Twig_SimpleTest('anonymous', function () {}));
|
||||
|
||||
return parent::getEnvironment();
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class Twig_Tests_Node_ForTest extends Twig_Test_NodeTestCase
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
// line 1
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('items')});
|
||||
foreach (\$context['_seq'] as \$context["key"] => \$context["item"]) {
|
||||
echo {$this->getVariableGetter('foo')};
|
||||
@@ -73,7 +73,7 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
// line 1
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('values')});
|
||||
\$context['loop'] = array(
|
||||
'parent' => \$context['_parent'],
|
||||
@@ -116,7 +116,7 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
// line 1
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('values')});
|
||||
\$context['loop'] = array(
|
||||
'parent' => \$context['_parent'],
|
||||
@@ -149,7 +149,7 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
// line 1
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_parent'] = \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable({$this->getVariableGetter('values')});
|
||||
\$context['_iterated'] = false;
|
||||
\$context['loop'] = array(
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__).'/../lib/Twig/Autoloader.php';
|
||||
require_once __DIR__.'/../lib/Twig/Autoloader.php';
|
||||
Twig_Autoloader::register(true);
|
||||
|
||||
Reference in New Issue
Block a user