Compiler.php
protected function compileCase(Node $node)
    {

        $subject = $node->subject;

        if ($this->isVariable($subject))
            $subject = "isset({$subject}) ? {$subject} : null";

        //Notice that we omit the "? >"
        //This is because PHP doesnt allow "? ><?php" between switch and the first case
        $phtml = $this->createCode("switch ({$subject}) {", '<?php ', '').$this->newLine();
        $phtml .= $this->compileChildren($node->children).$this->newLine();
        $phtml .= $this->indent().$this->createCode('}');


        //We need to check this after compilation, since there could be when: something children
        //that would be like [case children=[[something expands=[when]]] right now
        $hasChild = false;
        foreach ($node->children as $child) {

            if ($child->type !== 'when') {
                $this->throwException(
                    "The `case`-node (`switch`-equivalent) can only have `when`-node children (`case`-equivalent). ".
                    "A $child->type-node has been provided.",
                    $node
                );
            }

            $hasChild = true;
        }

        if (!$hasChild) {

            $this->throwException(
                "The `case`-node needs at least one `when`-node as a child. Empty `case`-blocks are not allowed as ".
                "they can't provide any functionality.",
                $node
            );
        }

        return $phtml;
    }
protected function compileCase(Node $node)
    {

        $subject = $node->subject;

        if ($this->isVariable($subject))
            $subject = "isset({$subject}) ? {$subject} : null";

        //Notice that we omit the "? >"
        //This is because PHP doesnt allow "? ><?php" between switch and the first case
        $phtml = $this->createCode("switch ({$subject}) {", '<?php ', '').$this->newLine();
        $phtml .= $this->compileChildren($node->children).$this->newLine();
        $phtml .= $this->indent().$this->createCode('}');


        //We need to check this after compilation, since there could be when: something children
        //that would be like [case children=[[something expands=[when]]] right now
        $hasChild = false;
        foreach ($node->children as $child) {

            if ($child->type !== 'when') {
                $this->throwException(
                    "The `case`-node (`switch`-equivalent) can only have `when`-node children (`case`-equivalent). ".
                    "A $child->type-node has been provided.",
                    $node
                );
            }

            $hasChild = true;
        }

        if (!$hasChild) {

            $this->throwException(
                "The `case`-node needs at least one `when`-node as a child. Empty `case`-blocks are not allowed as ".
                "they can't provide any functionality.",
                $node
            );
        }

        return $phtml;
    }
protected function compileCase ( Node $ node ) { $ subject = $ node -> subject ; if ( $ this -> isVariable ( $ subject ) ) $ subject = "isset({$subject}) ? {$subject} : null" ; //Notice that we omit the "? >" //This is because PHP doesnt allow "? ><?php" between switch and the first case $ phtml = $ this -> createCode ( "switch ({$subject}) {" , '<?php ' , '' ) . $ this -> newLine ( ) ; $ phtml .= $ this -> compileChildren ( $ node -> children ) . $ this -> newLine ( ) ; $ phtml .= $ this -> indent ( ) . $ this -> createCode ( '}' ) ; //We need to check this after compilation, since there could be when: something children //that would be like [case children=[[something expands=[when]]] right now $ hasChild = false ; foreach ( $ node -> children as $ child ) { if ( $ child -> type !== 'when' ) { $ this -> throwException ( "The `case`-node (`switch`-equivalent) can only have `when`-node children (`case`-equivalent). " . "A $child->type-node has been provided." , $ node ) ; } $ hasChild = true ; } if ( ! $ hasChild ) { $ this -> throwException ( "The `case`-node needs at least one `when`-node as a child. Empty `case`-blocks are not allowed as " . "they can't provide any functionality." , $ node ) ; } return $ phtml ; }
Compiles a case-node into PHTML.

This also checks if all sub-nodes of the case are
when-children, nothing else is allowed

compileCase interacts with compileWhen to skip ?><?php after the switch {

@param Node $node the case node to compile

@return string The compiled PHTML
@throws Exception
Compiles a case - node into PHTML .