mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-01 13:07:22 +00:00
Fix PHP 8 compat
This commit is contained in:
@@ -38,7 +38,6 @@ jobs:
|
||||
- php: 7.3
|
||||
- php: 7.4
|
||||
- php: nightly
|
||||
env: SYMFONY_PHPUNIT_VERSION=7.2
|
||||
- stage: integration tests
|
||||
php: 7.3
|
||||
script: ./drupal_test.sh
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# 1.43.0 (2020-XX-XX)
|
||||
|
||||
* Fix PHP 8 compatibility
|
||||
* Drop PHP 5.5 5.6, and 7.0 support
|
||||
* Fix ambiguous syntax parsing
|
||||
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
"keywords": ["templating"],
|
||||
"homepage": "https://twig.symfony.com",
|
||||
"license": "BSD-3-Clause",
|
||||
"minimum-stability": "dev",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
@@ -23,7 +24,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"php": "^7.1.3|^8.0",
|
||||
"symfony/polyfill-ctype": "^1.8"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
@@ -23,7 +23,7 @@ use Twig\Node\Expression\ConstantExpression;
|
||||
class EmbedNode extends IncludeNode
|
||||
{
|
||||
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
|
||||
public function __construct($name, $index, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
|
||||
public function __construct($name, $index, ?AbstractExpression $variables, $only, $ignoreMissing, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
|
||||
|
||||
|
||||
@@ -22,10 +22,7 @@ use Twig\Node\Node;
|
||||
*/
|
||||
class BlockReferenceExpression extends AbstractExpression
|
||||
{
|
||||
/**
|
||||
* @param Node|null $template
|
||||
*/
|
||||
public function __construct(\Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
|
||||
public function __construct(\Twig_NodeInterface $name, ?Node $template, $lineno, $tag = null)
|
||||
{
|
||||
if (\is_bool($template)) {
|
||||
@trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
@@ -254,7 +254,8 @@ abstract class CallExpression extends AbstractExpression
|
||||
}
|
||||
if ($isVariadic) {
|
||||
$argument = end($parameters);
|
||||
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
|
||||
$isArray = $argument && $argument->getType() && 'array' === (\PHP_VERSION_ID >= 70100 ? $argument->getType()->getName() : (string) $argument->getType());
|
||||
if ($isArray && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
|
||||
array_pop($parameters);
|
||||
} else {
|
||||
$callableName = $r->name;
|
||||
|
||||
@@ -25,7 +25,7 @@ class ForNode extends Node
|
||||
{
|
||||
protected $loop;
|
||||
|
||||
public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, \Twig_NodeInterface $body, \Twig_NodeInterface $else = null, $lineno, $tag = null)
|
||||
public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, ?AbstractExpression $ifexpr, ?\Twig_NodeInterface $body, ?\Twig_NodeInterface $else, $lineno, $tag = null)
|
||||
{
|
||||
$body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]);
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class IfNode extends Node
|
||||
{
|
||||
public function __construct(\Twig_NodeInterface $tests, \Twig_NodeInterface $else = null, $lineno, $tag = null)
|
||||
public function __construct(?\Twig_NodeInterface $tests, ?\Twig_NodeInterface $else, $lineno, $tag = null)
|
||||
{
|
||||
$nodes = ['tests' => $tests];
|
||||
if (null !== $else) {
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Node\Expression\AbstractExpression;
|
||||
*/
|
||||
class IncludeNode extends Node implements NodeOutputInterface
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
|
||||
public function __construct(AbstractExpression $expr, ?AbstractExpression $variables, $only, $ignoreMissing, $lineno, $tag = null)
|
||||
{
|
||||
$nodes = ['expr' => $expr];
|
||||
if (null !== $variables) {
|
||||
|
||||
@@ -20,7 +20,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class WithNode extends Node
|
||||
{
|
||||
public function __construct(Node $body, Node $variables = null, $only = false, $lineno, $tag = null)
|
||||
public function __construct(Node $body, ?Node $variables, $only, $lineno, $tag = null)
|
||||
{
|
||||
$nodes = ['body' => $body];
|
||||
if (null !== $variables) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
--TEST--
|
||||
Twig is able to deal with SimpleXMLElement instances as variables
|
||||
--CONDITION--
|
||||
version_compare(phpversion(), '5.3.0', '>=')
|
||||
version_compare(phpversion(), '8.0', '<')
|
||||
--TEMPLATE--
|
||||
Hello '{{ images.image.0.group }}'!
|
||||
{{ images.image.0.group.attributes.myattr }}
|
||||
|
||||
@@ -43,7 +43,6 @@ Twig supports the in operator
|
||||
{{ ''~dir_object in dir_object ? 'KO' : 'OK' }}
|
||||
|
||||
{{ resource in [''~resource] ? 'KO' : 'OK' }}
|
||||
{{ resource in [resource + 1 - 1] ? 'KO' : 'OK' }}
|
||||
{{ dir_object in [''~dir_object] ? 'KO' : 'OK' }}
|
||||
|
||||
{{ 5 in 125 ? 'KO' : 'OK' }}
|
||||
@@ -106,7 +105,6 @@ OK
|
||||
OK
|
||||
OK
|
||||
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ class CallTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
public function testResolveArgumentsWithMissingValueForOptionalArgument()
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
$this->markTestSkipped('substr_compare() has a default value in 8.0, so the test does not work anymore, one should find another PHP built-in function for this test to work in PHP 8.');
|
||||
}
|
||||
|
||||
$this->expectException('\Twig\Error\SyntaxError');
|
||||
$this->expectExceptionMessage('Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length".');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user