mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
deprecate passing a tag to ImportNode
This commit is contained in:
+11
-1
@@ -24,8 +24,18 @@ use Twig\Node\Expression\NameExpression;
|
||||
#[YieldReady]
|
||||
class ImportNode extends Node
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, ?string $tag = null, bool $global = true)
|
||||
/**
|
||||
* @param bool $global
|
||||
*/
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, $global = true)
|
||||
{
|
||||
if (null === $global || is_string($global)) {
|
||||
trigger_deprecation('twig/twig', '3.12', 'Passing a tag to %s() is deprecated.', __METHOD__);
|
||||
$global = func_num_args() > 4 ? func_get_arg(4) : true;
|
||||
} elseif (!is_bool($global)) {
|
||||
throw new \TypeError(\sprintf('Argument 4 passed to "%s()" must be a boolean, "%s" given.', __METHOD__, get_debug_type($global)));
|
||||
}
|
||||
|
||||
parent::__construct(['expr' => $expr, 'var' => $var], ['global' => $global], $lineno);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ final class MacroAutoImportNodeVisitor implements NodeVisitorInterface
|
||||
if ($node instanceof ModuleNode) {
|
||||
$this->inAModule = false;
|
||||
if ($this->hasMacroCalls) {
|
||||
$node->getNode('constructor_end')->setNode('_auto_macro_import', new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, null, true));
|
||||
$node->getNode('constructor_end')->setNode('_auto_macro_import', new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, true));
|
||||
}
|
||||
} elseif ($this->inAModule) {
|
||||
if (
|
||||
|
||||
@@ -50,7 +50,7 @@ final class FromTokenParser extends AbstractTokenParser
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$var = new AssignNameExpression($this->parser->getVarName(), $token->getLine());
|
||||
$node = new ImportNode($macro, $var, $token->getLine(), null, $this->parser->isMainScope());
|
||||
$node = new ImportNode($macro, $var, $token->getLine(), $this->parser->isMainScope());
|
||||
|
||||
foreach ($targets as $name => $alias) {
|
||||
$this->parser->addImportedSymbol('function', $alias, 'macro_'.$name, $var);
|
||||
|
||||
@@ -34,7 +34,7 @@ final class ImportTokenParser extends AbstractTokenParser
|
||||
|
||||
$this->parser->addImportedSymbol('template', $var->getAttribute('name'));
|
||||
|
||||
return new ImportNode($macro, $var, $token->getLine(), null, $this->parser->isMainScope());
|
||||
return new ImportNode($macro, $var, $token->getLine(), $this->parser->isMainScope());
|
||||
}
|
||||
|
||||
public function getTag(): string
|
||||
|
||||
Reference in New Issue
Block a user