for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Goetas\Twital\Node;
use Goetas\Twital\Compiler;
use Goetas\Twital\Exception;
use Goetas\Twital\Helper\DOMHelper;
use Goetas\Twital\Node;
/**
*
* @author Asmir Mustafic <[email protected]>
*/
class MacroNode implements Node
{
public function visit(\DOMElement $node, Compiler $context)
if (!$node->hasAttribute("name")) {
throw new Exception("Name attribute is required");
}
$context->compileChilds($node);
$set = iterator_to_array($node->childNodes);
$start = $context->createControlNode("macro " . $node->getAttribute("name") . "(" . $node->getAttribute("args") . ")");
array_unshift($set, $start);
$set[] = $context->createControlNode("endmacro");
DOMHelper::replaceWithSet($node, $set);