Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -23,12 +23,12 @@ class DumpNode extends Node
public function __construct($varPrefix, Node $values = null, $lineno, $tag = null)
{
$nodes = array();
$nodes = [];
if (null !== $values) {
$nodes['values'] = $values;
}
parent::__construct($nodes, array(), $lineno, $tag);
parent::__construct($nodes, [], $lineno, $tag);
$this->varPrefix = $varPrefix;
}
@@ -44,7 +44,7 @@ class DumpNode extends Node
if (!$this->hasNode('values')) {
// remove embedded templates (macros) from the context
$compiler
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
->write(sprintf('$%svars = [];'."\n", $this->varPrefix))
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
->indent()
->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
@@ -65,7 +65,7 @@ class DumpNode extends Node
} else {
$compiler
->addDebugInfo($this)
->write('\Symfony\Component\VarDumper\VarDumper::dump(array('."\n")
->write('\Symfony\Component\VarDumper\VarDumper::dump(['."\n")
->indent();
foreach ($values as $node) {
$compiler->write('');
@@ -80,7 +80,7 @@ class DumpNode extends Node
}
$compiler
->outdent()
->write("));\n");
->write("]);\n");
}
$compiler

View File

@@ -11,7 +11,10 @@
namespace Symfony\Bridge\Twig\Node;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Component\Form\FormRenderer;
use Twig\Compiler;
use Twig\Error\RuntimeError;
use Twig\Node\Node;
/**
@@ -19,19 +22,30 @@ use Twig\Node\Node;
*/
class FormThemeNode extends Node
{
public function __construct(Node $form, Node $resources, $lineno, $tag = null)
public function __construct(Node $form, Node $resources, $lineno, $tag = null, $only = false)
{
parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag);
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => (bool) $only], $lineno, $tag);
}
public function compile(Compiler $compiler)
{
try {
$compiler->getEnvironment()->getRuntime(FormRenderer::class);
$renderer = FormRenderer::class;
} catch (RuntimeError $e) {
$renderer = TwigRenderer::class;
}
$compiler
->addDebugInfo($this)
->write('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->setTheme(')
->write('$this->env->getRuntime(')
->string($renderer)
->raw(')->setTheme(')
->subcompile($this->getNode('form'))
->raw(', ')
->subcompile($this->getNode('resources'))
->raw(', ')
->raw(false === $this->getAttribute('only') ? 'true' : 'false')
->raw(");\n");
}
}

View File

@@ -28,7 +28,7 @@ class RenderBlockNode extends FunctionExpression
{
$compiler->addDebugInfo($this);
$arguments = iterator_to_array($this->getNode('arguments'));
$compiler->write('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->renderBlock(');
$compiler->write('$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->renderBlock(');
if (isset($arguments[0])) {
$compiler->subcompile($arguments[0]);

View File

@@ -24,11 +24,10 @@ class SearchAndRenderBlockNode extends FunctionExpression
public function compile(Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->raw('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(');
$compiler->raw('$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(');
preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches);
$label = null;
$arguments = iterator_to_array($this->getNode('arguments'));
$blockNameSuffix = $matches[1];
@@ -53,7 +52,7 @@ class SearchAndRenderBlockNode extends FunctionExpression
// Only insert the label into the array if it is not empty
if (!twig_test_empty($label->getAttribute('value'))) {
$originalVariables = $variables;
$variables = new ArrayExpression(array(), $lineno);
$variables = new ArrayExpression([], $lineno);
$labelKey = new ConstantExpression('label', $lineno);
if (null !== $originalVariables) {
@@ -100,7 +99,7 @@ class SearchAndRenderBlockNode extends FunctionExpression
// If not, add it to the array at runtime.
$compiler->raw('(twig_test_empty($_label_ = ');
$compiler->subcompile($label);
$compiler->raw(') ? array() : array("label" => $_label_))');
$compiler->raw(') ? [] : ["label" => $_label_])');
}
}
}

View File

@@ -24,7 +24,7 @@ class StopwatchNode extends Node
{
public function __construct(Node $name, Node $body, AssignNameExpression $var, $lineno = 0, $tag = null)
{
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
}
public function compile(Compiler $compiler)

View File

@@ -22,7 +22,7 @@ class TransDefaultDomainNode extends Node
{
public function __construct(AbstractExpression $expr, $lineno = 0, $tag = null)
{
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
parent::__construct(['expr' => $expr], [], $lineno, $tag);
}
public function compile(Compiler $compiler)

View File

@@ -29,7 +29,7 @@ class TransNode extends Node
{
public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, $lineno = 0, $tag = null)
{
$nodes = array('body' => $body);
$nodes = ['body' => $body];
if (null !== $domain) {
$nodes['domain'] = $domain;
}
@@ -43,14 +43,14 @@ class TransNode extends Node
$nodes['locale'] = $locale;
}
parent::__construct($nodes, array(), $lineno, $tag);
parent::__construct($nodes, [], $lineno, $tag);
}
public function compile(Compiler $compiler)
{
$compiler->addDebugInfo($this);
$defaults = new ArrayExpression(array(), -1);
$defaults = new ArrayExpression([], -1);
if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof ArrayExpression) {
$defaults = $this->getNode('vars');
$vars = null;
@@ -109,7 +109,7 @@ class TransNode extends Node
} elseif ($body instanceof TextNode) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
return [$body, $vars];
}
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
@@ -127,6 +127,6 @@ class TransNode extends Node
}
}
return array(new ConstantExpression(str_replace('%%', '%', trim($msg)), $body->getTemplateLine()), $vars);
return [new ConstantExpression(str_replace('%%', '%', trim($msg)), $body->getTemplateLine()), $vars];
}
}