-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #4402 Rework macros handling (fabpot)
This PR was squashed before being merged into the 3.x branch. Discussion ---------- Rework macros handling Commits ------- f1481be Remove MacroAutoImportNodeVisitor 7269388 Simplify code 1105964 Rework macros handling
- Loading branch information
Showing
21 changed files
with
317 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Twig\Node\Expression; | ||
|
||
use Twig\Compiler; | ||
use Twig\Node\Expression\Variable\TemplateVariable; | ||
|
||
/** | ||
* Represents a macro call node. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class MacroReferenceExpression extends AbstractExpression | ||
{ | ||
public function __construct(TemplateVariable $template, string $name, AbstractExpression $arguments, int $lineno) | ||
{ | ||
parent::__construct(['template' => $template, 'arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); | ||
} | ||
|
||
public function compile(Compiler $compiler): void | ||
{ | ||
if ($this->getAttribute('is_defined_test')) { | ||
$compiler | ||
->subcompile($this->getNode('template')) | ||
->raw('->hasMacro(') | ||
->repr($this->getAttribute('name')) | ||
->raw(', $context') | ||
->raw(')') | ||
; | ||
|
||
return; | ||
} | ||
|
||
$compiler | ||
->subcompile($this->getNode('template')) | ||
->raw('->getTemplateForMacro(') | ||
->repr($this->getAttribute('name')) | ||
->raw(', $context, ') | ||
->repr($this->getTemplateLine()) | ||
->raw(', $this->getSourceContext())') | ||
->raw(\sprintf('->%s', $this->getAttribute('name'))) | ||
->raw('(...') | ||
->subcompile($this->getNode('arguments')) | ||
->raw(')') | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Twig\Node\Expression\Variable; | ||
|
||
use Twig\Compiler; | ||
use Twig\Node\Expression\NameExpression; | ||
|
||
final class TemplateVariable extends NameExpression | ||
{ | ||
public function compile(Compiler $compiler): void | ||
{ | ||
if ('_self' === $this->getAttribute('name')) { | ||
$compiler->raw('$this'); | ||
} else { | ||
$compiler | ||
->raw('$macros[') | ||
->string($this->getAttribute('name')) | ||
->raw(']') | ||
; | ||
} | ||
} | ||
} |
Oops, something went wrong.