winter/modules/cms/twig/PutNode.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace Cms\Twig;
use Twig\Node\Node as TwigNode;
use Twig\Compiler as TwigCompiler;
2014-05-14 23:24:20 +10:00
/**
* Represents a put node
*
* @package october\cms
* @author Alexey Bobkov, Samuel Georges
*/
class PutNode extends TwigNode
2014-05-14 23:24:20 +10:00
{
public function __construct(TwigNode $body, $name, $endType, $lineno, $tag = 'put')
2014-05-14 23:24:20 +10:00
{
parent::__construct(['body' => $body], ['name' => $name, 'endType' => $endType], $lineno, $tag);
2014-05-14 23:24:20 +10:00
}
/**
* Compiles the node to PHP.
*
* @param TwigCompiler $compiler A TwigCompiler instance
2014-05-14 23:24:20 +10:00
*/
public function compile(TwigCompiler $compiler)
2014-05-14 23:24:20 +10:00
{
$compiler
->addDebugInfo($this)
2017-05-13 09:34:20 +10:00
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->startBlock(")
2014-05-14 23:24:20 +10:00
->raw("'".$this->getAttribute('name')."'")
->write(");\n")
;
$isOverwrite = strtolower($this->getAttribute('endType')) == 'overwrite';
2014-05-14 23:24:20 +10:00
$compiler->subcompile($this->getNode('body'));
$compiler
->addDebugInfo($this)
2017-05-13 09:34:20 +10:00
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->endBlock(")
->raw($isOverwrite ? 'false' : 'true')
->write(");\n")
2014-10-11 01:42:04 +02:00
;
2014-05-14 23:24:20 +10:00
}
2014-10-11 01:42:04 +02:00
}