From 4f8c480d0704370cba21126a8ac0956b1b8c7a4c Mon Sep 17 00:00:00 2001 From: Jan Rosier Date: Sat, 12 Jan 2019 21:19:44 +0100 Subject: [PATCH] Remove pre PHP v5.3 code --- lib/Twig/Autoloader.php | 6 +-- lib/Twig/Cache/Filesystem.php | 4 +- lib/Twig/Error.php | 14 +------ lib/Twig/Error/Loader.php | 8 +--- lib/Twig/Extension/Core.php | 55 ++++++++------------------- lib/Twig/Test/IntegrationTestCase.php | 10 ++--- 6 files changed, 24 insertions(+), 73 deletions(-) diff --git a/lib/Twig/Autoloader.php b/lib/Twig/Autoloader.php index 7fae00e51..6a2bf4a60 100644 --- a/lib/Twig/Autoloader.php +++ b/lib/Twig/Autoloader.php @@ -29,11 +29,7 @@ class Twig_Autoloader { @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED); - if (PHP_VERSION_ID < 50300) { - spl_autoload_register([__CLASS__, 'autoload']); - } else { - spl_autoload_register([__CLASS__, 'autoload'], true, $prepend); - } + spl_autoload_register([__CLASS__, 'autoload'], true, $prepend); } /** diff --git a/lib/Twig/Cache/Filesystem.php b/lib/Twig/Cache/Filesystem.php index 65976282b..5b0acc073 100644 --- a/lib/Twig/Cache/Filesystem.php +++ b/lib/Twig/Cache/Filesystem.php @@ -50,9 +50,7 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface $dir = dirname($key); if (!is_dir($dir)) { if (false === @mkdir($dir, 0777, true)) { - if (PHP_VERSION_ID >= 50300) { - clearstatcache(true, $dir); - } + clearstatcache(true, $dir); if (!is_dir($dir)) { throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); } diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 3a8c96c9e..0b8a92ec1 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -71,12 +71,7 @@ class Twig_Error extends Exception $this->sourceCode = $source->getCode(); $this->sourcePath = $source->getPath(); } - if (PHP_VERSION_ID < 50300) { - $this->previous = $previous; - parent::__construct(''); - } else { - parent::__construct('', 0, $previous); - } + parent::__construct('', 0, $previous); $this->lineno = $lineno; $this->filename = $name; @@ -296,12 +291,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']); diff --git a/lib/Twig/Error/Loader.php b/lib/Twig/Error/Loader.php index df566dd78..2ef0480e3 100644 --- a/lib/Twig/Error/Loader.php +++ b/lib/Twig/Error/Loader.php @@ -26,12 +26,8 @@ class Twig_Error_Loader extends Twig_Error { public function __construct($message, $lineno = -1, $source = null, Exception $previous = null) { - if (PHP_VERSION_ID < 50300) { - $this->previous = $previous; - Exception::__construct(''); - } else { - Exception::__construct('', 0, $previous); - } + Exception::__construct('', 0, $previous); + $this->appendMessage($message); $this->setTemplateLine(false); } diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 67d91bead..9babcfc6e 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -562,44 +562,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) @@ -1116,10 +1095,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: diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index b12c57665..31db139c6 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -171,13 +171,9 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase $twig->addFunction($function); } - // avoid using the same PHP class name for different cases - // only for PHP 5.2+ - if (PHP_VERSION_ID >= 50300) { - $p = new ReflectionProperty($twig, 'templateClassPrefix'); - $p->setAccessible(true); - $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); - } + $p = new ReflectionProperty($twig, 'templateClassPrefix'); + $p->setAccessible(true); + $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); try { $template = $twig->loadTemplate('index.twig');