mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-10 22:05:44 +00:00
Merge branch '2.x' into 3.x
* 2.x: macros imported "globally" in a template are now available in macros without re-importing them added more tests added some tests
This commit is contained in:
+13
-5
@@ -22,19 +22,27 @@ use Twig\Node\Expression\NameExpression;
|
||||
*/
|
||||
class ImportNode extends Node
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, string $tag = null)
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, string $tag = null, bool $global = true)
|
||||
{
|
||||
parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag);
|
||||
parent::__construct(['expr' => $expr, 'var' => $var], ['global' => $global], $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('')
|
||||
->subcompile($this->getNode('var'))
|
||||
->raw(' = ')
|
||||
->write('$macros[')
|
||||
->repr($this->getNode('var')->getAttribute('name'))
|
||||
->raw('] = ')
|
||||
;
|
||||
|
||||
if ($this->getAttribute('global')) {
|
||||
$compiler
|
||||
->raw('$this->macros[')
|
||||
->repr($this->getNode('var')->getAttribute('name'))
|
||||
->raw('] = ')
|
||||
;
|
||||
}
|
||||
|
||||
if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) {
|
||||
$compiler->raw('$this');
|
||||
|
||||
Reference in New Issue
Block a user