2014-05-14 13:24:20 +00:00
|
|
|
<?php namespace Cms\Twig;
|
|
|
|
|
|
2019-03-27 19:15:17 +00:00
|
|
|
use Twig\Node\Node as TwigNode;
|
|
|
|
|
use Twig\Compiler as TwigCompiler;
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents a component node
|
|
|
|
|
*
|
|
|
|
|
* @package october\cms
|
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
|
*/
|
2019-03-27 19:15:17 +00:00
|
|
|
class ComponentNode extends TwigNode
|
2014-05-14 13:24:20 +00:00
|
|
|
{
|
2019-03-27 19:15:17 +00:00
|
|
|
public function __construct(TwigNode $nodes, $paramNames, $lineno, $tag = 'component')
|
2014-05-14 13:24:20 +00:00
|
|
|
{
|
2014-05-22 10:27:44 +00:00
|
|
|
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compiles the node to PHP.
|
|
|
|
|
*
|
2019-03-27 19:15:17 +00:00
|
|
|
* @param TwigCompiler $compiler A TwigCompiler instance
|
2014-05-14 13:24:20 +00:00
|
|
|
*/
|
2019-03-27 19:15:17 +00:00
|
|
|
public function compile(TwigCompiler $compiler)
|
2014-05-14 13:24:20 +00:00
|
|
|
{
|
2014-05-22 10:27:44 +00:00
|
|
|
$compiler->addDebugInfo($this);
|
|
|
|
|
|
|
|
|
|
$compiler->write("\$context['__cms_component_params'] = [];\n");
|
|
|
|
|
|
|
|
|
|
for ($i = 1; $i < count($this->getNode('nodes')); $i++) {
|
|
|
|
|
$compiler->write("\$context['__cms_component_params']['".$this->getAttribute('names')[$i-1]."'] = ");
|
|
|
|
|
$compiler->subcompile($this->getNode('nodes')->getNode($i));
|
|
|
|
|
$compiler->write(";\n");
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
$compiler
|
2017-05-12 23:34:20 +00:00
|
|
|
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->componentFunction(")
|
2014-05-22 10:27:44 +00:00
|
|
|
->subcompile($this->getNode('nodes')->getNode(0))
|
|
|
|
|
->write(", \$context['__cms_component_params']")
|
2014-05-14 13:24:20 +00:00
|
|
|
->write(");\n")
|
|
|
|
|
;
|
2014-05-22 10:27:44 +00:00
|
|
|
|
|
|
|
|
$compiler->write("unset(\$context['__cms_component_params']);\n");
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
2014-10-10 23:42:04 +00:00
|
|
|
}
|