Tale\Jade\Parser\Node::prev PHP Method

prev() public method

[element:a] (0)[element:b] (1)[element:c] [element:c]->prev() === [element:b]
public prev ( ) : Node | null
return Node | null
    public function prev()
    {
        $index = $this->parent->indexOf($this) - 1;
        return isset($this->parent->children[$index]) ? $this->parent->children[$index] : null;
    }

Usage Example

示例#1
0
 /**
  * Compiles a while-loop into PHTML.
  *
  * Notice that if it has no children, we assume it's a do/while loop
  * and don't print brackets
  *
  * @param Node $node the while-node to compile
  *
  * @return string The compiled PHTML
  */
 protected function compileWhile(Node $node)
 {
     $subject = $node->subject;
     if ($this->isVariable($subject)) {
         $subject = "isset({$subject}) ? {$subject} : null";
     }
     $hasChildren = count($node->children) > 0;
     $isDoWhile = $node->prev() && $node->prev()->type === 'do';
     if (!$hasChildren && !$isDoWhile) {
         $this->throwException('A while-loop without children you loop through is not valid if' . ' there\'s no do-statement before it.', $node);
     } else {
         if ($isDoWhile && $hasChildren) {
             $this->throwException('In a do-while statement the while-part shouldn\'t have any children', $node);
         }
     }
     $phtml = $this->createCode("while ({$subject})" . ($hasChildren ? ' {' : ''), $isDoWhile ? ' ' : '<?php ') . $this->newLine();
     if ($hasChildren) {
         $phtml .= $this->compileChildren($node->children) . $this->newLine();
         $phtml .= $this->indent() . $this->createCode('}') . $this->newLine();
     }
     return $phtml;
 }
All Usage Examples Of Tale\Jade\Parser\Node::prev