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

        if (!$node->parent || $node->parent->type !== 'case')
            $this->throwException(
                "A `when`-node can only be a direct descendant of a `case`-node. This one is a child of a ".
                "{$node->parent->type}-node. Maybe you wanted to use `if/unless`?",
                $node
            );

        $subject = $node->subject;

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

        $first = $node->parent->indexOf($node) === 0;

        //If this is the first node, we omit the prefix for the code "<?php"
        //Notice that compileCase omits the ? >, so it fits together here
        $phtml = $this->createCode($node->default ? 'default:' : "case $subject:", $first ? '' : '<?php ').$this->newLine();
        $phtml .= $this->compileChildren($node->children).$this->newLine();

        if (count($node->children) > 0)
            $phtml .= $this->indent().$this->createCode('break;');

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

        if (!$node->parent || $node->parent->type !== 'case')
            $this->throwException(
                "A `when`-node can only be a direct descendant of a `case`-node. This one is a child of a ".
                "{$node->parent->type}-node. Maybe you wanted to use `if/unless`?",
                $node
            );

        $subject = $node->subject;

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

        $first = $node->parent->indexOf($node) === 0;

        //If this is the first node, we omit the prefix for the code "<?php"
        //Notice that compileCase omits the ? >, so it fits together here
        $phtml = $this->createCode($node->default ? 'default:' : "case $subject:", $first ? '' : '<?php ').$this->newLine();
        $phtml .= $this->compileChildren($node->children).$this->newLine();

        if (count($node->children) > 0)
            $phtml .= $this->indent().$this->createCode('break;');

        return $phtml;
    }
protected function compileWhen ( Node $ node ) { if ( ! $ node -> parent || $ node -> parent -> type !== 'case' ) $ this -> throwException ( "A `when`-node can only be a direct descendant of a `case`-node. This one is a child of a " . "{$node->parent->type}-node. Maybe you wanted to use `if/unless`?" , $ node ) ; $ subject = $ node -> subject ; if ( $ subject && $ this -> isVariable ( $ subject ) ) $ subject = "isset({$subject}) ? {$subject} : null" ; $ first = $ node -> parent -> indexOf ( $ node ) === 0 ; //If this is the first node, we omit the prefix for the code "<?php" //Notice that compileCase omits the ? >, so it fits together here $ phtml = $ this -> createCode ( $ node -> default ? 'default:' : "case $subject:" , $ first ? '' : '<?php ' ) . $ this -> newLine ( ) ; $ phtml .= $ this -> compileChildren ( $ node -> children ) . $ this -> newLine ( ) ; if ( count ( $ node -> children ) > 0 ) $ phtml .= $ this -> indent ( ) . $ this -> createCode ( 'break;' ) ; return $ phtml ; }
Compiles a when-node into PHTML.

This also checks, if the when node is defined
on a case-parent

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

@param Node $node the when-node to compile

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