mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php namespace Cms\Twig;
|
|
|
|
use Twig\Node\Node as TwigNode;
|
|
use Twig\Compiler as TwigCompiler;
|
|
|
|
/**
|
|
* Represents a partial node
|
|
*
|
|
* @package wintercms\wn-cms-module
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
*/
|
|
class PartialNode extends TwigNode
|
|
{
|
|
public function __construct(TwigNode $nodes, $paramNames, $lineno, $tag = 'partial')
|
|
{
|
|
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
|
|
}
|
|
|
|
/**
|
|
* Compiles the node to PHP.
|
|
*
|
|
* @param TwigCompiler $compiler A TwigCompiler instance
|
|
*/
|
|
public function compile(TwigCompiler $compiler)
|
|
{
|
|
$compiler->addDebugInfo($this);
|
|
|
|
$compiler->write("\$context['__cms_partial_params'] = [];\n");
|
|
|
|
for ($i = 1; $i < count($this->getNode('nodes')); $i++) {
|
|
$compiler->write("\$context['__cms_partial_params']['".$this->getAttribute('names')[$i-1]."'] = ");
|
|
$compiler->subcompile($this->getNode('nodes')->getNode($i));
|
|
$compiler->write(";\n");
|
|
}
|
|
|
|
$compiler
|
|
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->partialFunction(")
|
|
->subcompile($this->getNode('nodes')->getNode(0))
|
|
->write(", \$context['__cms_partial_params']")
|
|
->write(", true")
|
|
->write(");\n")
|
|
;
|
|
|
|
$compiler->write("unset(\$context['__cms_partial_params']);\n");
|
|
}
|
|
}
|