ORIENT/modules/cms/twig/ComponentNode.php

46 lines
1.4 KiB
PHP
Raw Normal View History

2014-05-14 13:24:20 +00:00
<?php namespace Cms\Twig;
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
*/
class ComponentNode extends TwigNode
2014-05-14 13:24:20 +00:00
{
public function __construct(TwigNode $nodes, $paramNames, $lineno, $tag = 'component')
2014-05-14 13:24:20 +00:00
{
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
2014-05-14 13:24:20 +00:00
}
/**
* Compiles the node to PHP.
*
* @param TwigCompiler $compiler A TwigCompiler instance
2014-05-14 13:24:20 +00:00
*/
public function compile(TwigCompiler $compiler)
2014-05-14 13:24:20 +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(")
->subcompile($this->getNode('nodes')->getNode(0))
->write(", \$context['__cms_component_params']")
2014-05-14 13:24:20 +00:00
->write(");\n")
;
$compiler->write("unset(\$context['__cms_component_params']);\n");
2014-05-14 13:24:20 +00:00
}
2014-10-10 23:42:04 +00:00
}