mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -11,29 +11,44 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Attribute\FirstClassTwigCallableReady;
|
||||
use Twig\Attribute\YieldReady;
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\Variable\LocalVariable;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* @author Julien Galenski <julien.galenski@gmail.com>
|
||||
*/
|
||||
#[YieldReady]
|
||||
final class DumpNode extends Node
|
||||
{
|
||||
private string $varPrefix;
|
||||
private LocalVariable|string $varPrefix;
|
||||
|
||||
public function __construct(string $varPrefix, ?Node $values, int $lineno, string $tag = null)
|
||||
public function __construct(LocalVariable|string $varPrefix, ?Node $values, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$nodes = [];
|
||||
if (null !== $values) {
|
||||
$nodes['values'] = $values;
|
||||
}
|
||||
|
||||
parent::__construct($nodes, [], $lineno, $tag);
|
||||
if (class_exists(FirstClassTwigCallableReady::class)) {
|
||||
parent::__construct($nodes, [], $lineno);
|
||||
} else {
|
||||
parent::__construct($nodes, [], $lineno, $tag);
|
||||
}
|
||||
|
||||
$this->varPrefix = $varPrefix;
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
if ($this->varPrefix instanceof LocalVariable) {
|
||||
$varPrefix = $this->varPrefix->getAttribute('name');
|
||||
} else {
|
||||
$varPrefix = $this->varPrefix;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->write("if (\$this->env->isDebug()) {\n")
|
||||
->indent();
|
||||
@@ -41,18 +56,18 @@ final class DumpNode extends Node
|
||||
if (!$this->hasNode('values')) {
|
||||
// remove embedded templates (macros) from the context
|
||||
$compiler
|
||||
->write(sprintf('$%svars = [];'."\n", $this->varPrefix))
|
||||
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
|
||||
->write(\sprintf('$%svars = [];'."\n", $varPrefix))
|
||||
->write(\sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $varPrefix))
|
||||
->indent()
|
||||
->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
|
||||
->write(\sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $varPrefix))
|
||||
->indent()
|
||||
->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
|
||||
->write(\sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $varPrefix))
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->addDebugInfo($this)
|
||||
->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix));
|
||||
->write(\sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $varPrefix));
|
||||
} elseif (($values = $this->getNode('values')) && 1 === $values->count()) {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
|
||||
@@ -12,17 +12,24 @@
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Symfony\Component\Form\FormRenderer;
|
||||
use Twig\Attribute\FirstClassTwigCallableReady;
|
||||
use Twig\Attribute\YieldReady;
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
#[YieldReady]
|
||||
final class FormThemeNode extends Node
|
||||
{
|
||||
public function __construct(Node $form, Node $resources, int $lineno, string $tag = null, bool $only = false)
|
||||
public function __construct(Node $form, Node $resources, int $lineno, ?string $tag = null, bool $only = false)
|
||||
{
|
||||
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag);
|
||||
if (class_exists(FirstClassTwigCallableReady::class)) {
|
||||
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno);
|
||||
} else {
|
||||
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Extension\CoreExtension;
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\FunctionExpression;
|
||||
@@ -50,7 +51,7 @@ final class SearchAndRenderBlockNode extends FunctionExpression
|
||||
$labelIsExpression = false;
|
||||
|
||||
// Only insert the label into the array if it is not empty
|
||||
if (!twig_test_empty($label->getAttribute('value'))) {
|
||||
if (null !== $label->getAttribute('value') && false !== $label->getAttribute('value') && '' !== (string) $label->getAttribute('value')) {
|
||||
$originalVariables = $variables;
|
||||
$variables = new ArrayExpression([], $lineno);
|
||||
$labelKey = new ConstantExpression('label', $lineno);
|
||||
@@ -97,7 +98,12 @@ final class SearchAndRenderBlockNode extends FunctionExpression
|
||||
|
||||
// Check at runtime whether the label is empty.
|
||||
// If not, add it to the array at runtime.
|
||||
$compiler->raw('(twig_test_empty($_label_ = ');
|
||||
if (method_exists(CoreExtension::class, 'testEmpty')) {
|
||||
$compiler->raw('(CoreExtension::testEmpty($_label_ = ');
|
||||
} else {
|
||||
$compiler->raw('(twig_test_empty($_label_ = ');
|
||||
}
|
||||
|
||||
$compiler->subcompile($label);
|
||||
$compiler->raw(') ? [] : ["label" => $_label_])');
|
||||
}
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Attribute\FirstClassTwigCallableReady;
|
||||
use Twig\Attribute\YieldReady;
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\Expression\Variable\LocalVariable;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
@@ -20,11 +23,23 @@ use Twig\Node\Node;
|
||||
*
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
#[YieldReady]
|
||||
final class StopwatchNode extends Node
|
||||
{
|
||||
public function __construct(Node $name, Node $body, AssignNameExpression $var, int $lineno = 0, string $tag = null)
|
||||
/**
|
||||
* @param AssignNameExpression|LocalVariable $var
|
||||
*/
|
||||
public function __construct(Node $name, Node $body, $var, int $lineno = 0, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
|
||||
if (!$var instanceof AssignNameExpression && !$var instanceof LocalVariable) {
|
||||
throw new \TypeError(\sprintf('Expected an instance of "%s" or "%s", but got "%s".', AssignNameExpression::class, LocalVariable::class, get_debug_type($var)));
|
||||
}
|
||||
|
||||
if (class_exists(FirstClassTwigCallableReady::class)) {
|
||||
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno);
|
||||
} else {
|
||||
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Attribute\FirstClassTwigCallableReady;
|
||||
use Twig\Attribute\YieldReady;
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\AbstractExpression;
|
||||
use Twig\Node\Node;
|
||||
@@ -18,11 +20,16 @@ use Twig\Node\Node;
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
#[YieldReady]
|
||||
final class TransDefaultDomainNode extends Node
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, int $lineno = 0, string $tag = null)
|
||||
public function __construct(AbstractExpression $expr, int $lineno = 0, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||
if (class_exists(FirstClassTwigCallableReady::class)) {
|
||||
parent::__construct(['expr' => $expr], [], $lineno);
|
||||
} else {
|
||||
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
|
||||
@@ -11,20 +11,24 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Attribute\FirstClassTwigCallableReady;
|
||||
use Twig\Attribute\YieldReady;
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\AbstractExpression;
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Node\Expression\Variable\ContextVariable;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\TextNode;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
#[YieldReady]
|
||||
final class TransNode extends Node
|
||||
{
|
||||
public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, int $lineno = 0, string $tag = null)
|
||||
public function __construct(Node $body, ?Node $domain = null, ?AbstractExpression $count = null, ?AbstractExpression $vars = null, ?AbstractExpression $locale = null, int $lineno = 0, ?string $tag = null)
|
||||
{
|
||||
$nodes = ['body' => $body];
|
||||
if (null !== $domain) {
|
||||
@@ -40,7 +44,11 @@ final class TransNode extends Node
|
||||
$nodes['locale'] = $locale;
|
||||
}
|
||||
|
||||
parent::__construct($nodes, [], $lineno, $tag);
|
||||
if (class_exists(FirstClassTwigCallableReady::class)) {
|
||||
parent::__construct($nodes, [], $lineno);
|
||||
} else {
|
||||
parent::__construct($nodes, [], $lineno, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
@@ -53,9 +61,10 @@ final class TransNode extends Node
|
||||
$vars = null;
|
||||
}
|
||||
[$msg, $defaults] = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
|
||||
$display = class_exists(YieldReady::class) ? 'yield' : 'echo';
|
||||
|
||||
$compiler
|
||||
->write('echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
|
||||
->write($display.' $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
|
||||
->subcompile($msg)
|
||||
;
|
||||
|
||||
@@ -118,7 +127,7 @@ final class TransNode extends Node
|
||||
if ('count' === $var && $this->hasNode('count')) {
|
||||
$vars->addElement($this->getNode('count'), $key);
|
||||
} else {
|
||||
$varExpr = new NameExpression($var, $body->getTemplateLine());
|
||||
$varExpr = class_exists(ContextVariable::class) ? new ContextVariable($var, $body->getTemplateLine()) : new NameExpression($var, $body->getTemplateLine());
|
||||
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
|
||||
$vars->addElement($varExpr, $key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user