public function compile(Compiler $compiler) { $compiler->scopeIn(Compiler::SCOPE_ROOT); $name = $this->getAttribute(self::ATTR_NAME); $compiler->write('<?php')->line()->write('class ' . $compiler->getEnvironment()->getTemplateClass($name) . ' extends Azera\\Fry\\Template {' . "\n")->line()->indent(); $this->renderTemplateName($compiler); $this->renderParentFunction($compiler); $this->renderBody($compiler); $this->renderBlocks($compiler); $this->renderMacros($compiler); $compiler->outdent()->line()->write('}'); $compiler->scopeOut(); }
public function compile(Compiler $compiler) { $env = $compiler->getEnvironment(); $functionName = $this->getAttribute(self::ATTR_NAME); /** @var Arguments $args */ $args = $this->getNode(self::NODE_ARGUMENTS); if ($env->hasFunction($functionName) && ($func = $env->getFunction($functionName)) instanceof NativeFunction) { $func->compile($compiler, $args); return; } if ($functionName == 'parent' && $compiler->isBlock()) { $compiler->raw('$this->parent->renderBlock(')->string($compiler->scopeName())->raw(' , $context )'); return; } if ($functionName == 'renderBlock') { if ($args->size() > 2) { throw new \LogicException(sprintf('Invalid renderBlock arguments count , %d , %d expected', $args->size(), 2)); } if ($args->size() < 1) { throw new \LogicException(sprintf('Invalid renderBlock, block name not defined')); } if ($args->size() == 2 && !$args->getNode(1) instanceof ArrayNode) { throw new \LogicException(sprintf('Invalid renderBlock, context must be array')); } $compiler->raw('$this->renderBlock(')->subcompile($args->getArgument(0))->raw(','); if ($args->size() == 2) { $compiler->raw('array_merge( $context , ')->subcompile($args->getArgument(1))->raw(')'); } else { $compiler->raw(' $context '); } if ($args) { $compiler->raw(')'); } return; } $compiler->raw('$this->getValue( $context , ')->raw('["' . implode('","', $this->convertToRoute($this->getAttribute(self::ATTR_NAME))) . '"]')->raw(' , self::METHOD_CALL , ')->subcompile($this->getNode(self::NODE_ARGUMENTS))->raw(')'); }