public function compile(Compiler $compiler) { $compiler->write('$this->set( $context , ')->raw('["' . implode('","', $this->convertToRoute($this->getAttribute(self::ATTR_VARIABLE))) . '"]')->raw(' , function() use ( $context ) {' . "\n")->indent(); if ($this->getAttribute(self::ATTR_IS_BLOCK)) { $compiler->writeln('ob_start();')->subcompile($this->getNode(self::NODE_VALUE))->writeln('return ob_get_clean();'); } else { $compiler->write('return ')->subcompile($this->getNode(self::NODE_VALUE))->raw(';' . "\n"); } $compiler->outdent()->writeln('});' . "\n"); }
public function compile(Compiler $compiler) { $args = $this->getNode(self::NODE_ARGS)->getNodes(); $macroName = $this->getAttribute(self::ATTR_NAME); $compiler->writeln('// Line ' . $this->getLineNo())->write('public function macro_' . $macroName)->scopeIn(Compiler::SCOPE_MACRO, $macroName)->raw('( $context = [] , $arguments = [] ) {')->line()->indent()->writeln('$args = [')->indent(); foreach ($args as $name => $value) { $compiler->write('')->string($name)->raw(' => '); if ($value) { $compiler->subcompile($value); } else { $compiler->raw('null'); } $compiler->raw(',')->line(); } $compiler->outdent()->writeln('];')->writeln('$context = array_merge( $context , $this->prepareArgs( $args , $arguments ) );')->subcompile($this->getNode(self::NODE_BODY))->scopeOut()->outdent()->writeln('}'); }
/** * @param Compiler $compiler */ public function compile(Compiler $compiler) { $compiler->writeln('/*')->writeln($this->getAttribute(self::ATTR_COMMENT))->writeln('*/'); }
public function compile(Compiler $compiler) { $key = $this->hasAttribute(self::ATTR_KEY) ? $this->getAttribute(self::ATTR_KEY) : 'key'; $value = $this->getAttribute(self::ATTR_VALUE); $compiler->writeln('$context["_parent"] = $context;')->writeln('$context["loop"] = [')->indent()->write('"items" => $_seq = $this->ensureTraversable(')->subcompile($this->getNode(self::NODE_REPO))->raw("),\n")->writeln('"index" => 0,')->writeln('"count" => count( $_seq ),')->outdent()->writeln('];')->write('foreach ( $context["loop"]["items"] as ')->raw("\${$key}")->raw(' => ')->raw("\${$value}")->raw(" ) { \n")->indent()->writeln(sprintf('$context["%s"] = $%s;', $key, $key))->writeln(sprintf('$context["%s"] = $%s;', $value, $value))->subcompile($this->getNode(self::NODE_BODY))->writeln('$context["loop"]["index"]++;')->outdent()->writeln('}')->writeln('$context = $context["_parent"];'); }
private function renderParentFunction(Compiler $compiler) { if ($this->hasParent()) { $parent = $this->getNode(self::NODE_PARENT); $compiler->writeln('// Line ' . $parent->getLineNo())->writeln('protected function getParent() {')->indent()->write('return ')->subcompile($parent)->raw(';')->line()->outdent()->writeln('}')->line(); } }
function compile(Compiler $compiler) { $compiler->writeln('$_sandbox = $context;'); $compiler->subcompile($this->body); $compiler->writeln('$context = $_sandbox;'); }
public function compile(Compiler $compiler) { $blockName = $this->getAttribute(self::ATTR_NAME); $compiler->writeln('// Line ' . $this->getLineNo())->writeln(sprintf('public function %s( array $context = array() ) {', $this->getMethodName()))->indent()->scopeIn(Compiler::SCOPE_BLOCK, $blockName)->writeln('ob_start();')->subcompile($this->getNode(self::NODE_BODY))->writeln('return ob_get_clean();')->scopeOut()->outdent()->writeln('}'); }