| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of Twig. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier |
| 7 |
* (c) Armin Ronacher |
| 8 |
* |
| 9 |
* For the full copyright and license information, please view the LICENSE |
| 10 |
* file that was distributed with this source code. |
| 11 |
*/ |
| 12 |
namespace ElementorDeps\Twig\Node\Expression; |
| 13 |
|
| 14 |
use ElementorDeps\Twig\Compiler; |
| 15 |
use ElementorDeps\Twig\Node\Node; |
| 16 |
/** |
| 17 |
* Represents a block call node. |
| 18 |
* |
| 19 |
* @author Fabien Potencier <fabien@symfony.com> |
| 20 |
*/ |
| 21 |
class BlockReferenceExpression extends AbstractExpression |
| 22 |
{ |
| 23 |
public function __construct(Node $name, ?Node $template, int $lineno, ?string $tag = null) |
| 24 |
{ |
| 25 |
$nodes = ['name' => $name]; |
| 26 |
if (null !== $template) { |
| 27 |
$nodes['template'] = $template; |
| 28 |
} |
| 29 |
parent::__construct($nodes, ['is_defined_test' => \false, 'output' => \false], $lineno, $tag); |
| 30 |
} |
| 31 |
public function compile(Compiler $compiler) : void |
| 32 |
{ |
| 33 |
if ($this->getAttribute('is_defined_test')) { |
| 34 |
$this->compileTemplateCall($compiler, 'hasBlock'); |
| 35 |
} else { |
| 36 |
if ($this->getAttribute('output')) { |
| 37 |
$compiler->addDebugInfo($this); |
| 38 |
$compiler->write('yield from '); |
| 39 |
$this->compileTemplateCall($compiler, 'yieldBlock')->raw(";\n"); |
| 40 |
} else { |
| 41 |
$this->compileTemplateCall($compiler, 'renderBlock'); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
private function compileTemplateCall(Compiler $compiler, string $method) : Compiler |
| 46 |
{ |
| 47 |
if (!$this->hasNode('template')) { |
| 48 |
$compiler->write('$this'); |
| 49 |
} else { |
| 50 |
$compiler->write('$this->loadTemplate(')->subcompile($this->getNode('template'))->raw(', ')->repr($this->getTemplateName())->raw(', ')->repr($this->getTemplateLine())->raw(')'); |
| 51 |
} |
| 52 |
$compiler->raw(\sprintf('->unwrap()->%s', $method)); |
| 53 |
return $this->compileBlockArguments($compiler); |
| 54 |
} |
| 55 |
private function compileBlockArguments(Compiler $compiler) : Compiler |
| 56 |
{ |
| 57 |
$compiler->raw('(')->subcompile($this->getNode('name'))->raw(', $context'); |
| 58 |
if (!$this->hasNode('template')) { |
| 59 |
$compiler->raw(', $blocks'); |
| 60 |
} |
| 61 |
return $compiler->raw(')'); |
| 62 |
} |
| 63 |
} |
| 64 |
|