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('}'); }
public function compile(Compiler $compiler, TagNode $node) { $first = true; $else = null; foreach ($node->getChildren() as $branch) { if ($first) { $compiler->indented('if('); $first = false; } elseif (!$branch->hasChild('condition')) { $else = $branch->getChild('body'); continue; } else { $compiler->add(' elseif('); } $compiler->compileNode($branch->getChild('condition'))->add(') {')->indent()->compileNode($branch->getChild('body'))->outdent()->indented('}'); } if ($else !== null) { $compiler->add(' else {')->indent()->compileNode($else)->outdent()->indented('}'); } }
public function compile(Compiler $compiler, TagNode $node) { $compiler->indented('unset')->compileArgumentList($node->getChildren())->add(';'); }