mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-10 09:26:29 +00:00
Remove pre PHP v5.3 code
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
+2
-12
@@ -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']);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+15
-40
@@ -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:
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user