public function compile(Compiler $compiler, TagNode $node) { $compiler->indented('switch(')->compileNode($node->getData('tested'))->add(')')->add(' {')->indent(); foreach ($node->getChildren() as $branch) { if (!$branch->hasChild('condition')) { $compiler->indented('default:'); } else { $compiler->indented('case ')->compileNode($branch->getChild('condition'))->add(':'); } $compiler->indent()->compileNode($branch->getChild('body'))->indented('break;')->outdent(); } $compiler->outdent()->indented('}'); }
private function compileBlock(Compiler $compiler, $method, RootNode $body) { $compiler->indented('public function %s(Context $context)', $method); $compiler->indented('{'); $compiler->indent(); if (!$body->hasData('environment_accessed') || $body->getData('environment_accessed')) { $compiler->indented('$environment = $this->getEnvironment();'); } $compiler->compileNode($body); $compiler->outdent(); $compiler->indented("}\n"); }