winter/modules/cms/twig/FlashNode.php
Pascal Borreli 459c8e0cfa Fixed typos
2014-05-17 18:08:01 +02:00

69 lines
2.0 KiB
PHP

<?php namespace Cms\Twig;
use Twig_Node;
use Twig_Compiler;
use Twig_NodeInterface;
use Twig_Node_Expression;
/**
* Represents a flash node
*
* @package october\cms
* @author Alexey Bobkov, Samuel Georges
*/
class FlashNode extends Twig_Node
{
public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = 'flash')
{
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$attrib = $this->getAttribute('name');
$compiler
->write('$_type = isset($context["type"]) ? $context["type"] : null;')
->write('$_message = isset($context["message"]) ? $context["message"] : null;')
;
if ($attrib == 'all') {
$compiler
->addDebugInfo($this)
->write('foreach (Flash::all() as $type => $message) {'.PHP_EOL)
->indent()
->write('$context["type"] = $type;')
->write('$context["message"] = $message;')
->subcompile($this->getNode('body'))
->outdent()
->write('}'.PHP_EOL)
;
}
else {
$compiler
->addDebugInfo($this)
->write('$context["type"] = ')
->string($attrib)
->write(';')
->write('foreach (Flash::')
->raw($attrib)
->write('() as $messages) {'.PHP_EOL)
->indent()
->write('$context["message"] = $message;')
->subcompile($this->getNode('body'))
->outdent()
->write('}'.PHP_EOL)
;
}
$compiler
->write('$context["type"] = $_type;')
->write('$context["message"] = $_message;')
;
}
}