mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
69 lines
2.0 KiB
PHP
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;')
|
|
;
|
|
}
|
|
} |