Tale\Jade\Parser\Node::prepend PHP Метод

prepend() публичный Метод

This also sets the parent of the given child to this node [element:a] (0)[element:b] (1)[element:c] [element:a]->prepend([element:d]) [element:a] (0)[element:d] (1)[element:b] (2)[element:c]
public prepend ( Node $node )
$node Node the new child node to be prepended
    public function prepend(Node $node)
    {
        array_unshift($this->children, $node);
        $node->parent = $this;
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * Stacks blocks into each other.
  *
  * The first block found is always the container,
  * all other blocks either to append, replace or prepend
  * to/the first block.
  *
  * @param Node $node the block node to handle
  *
  * @return $this
  */
 protected function handleBlock(Node $node)
 {
     if (!$node->name || $node->mode === 'ignore') {
         //Will be handled through compileBlock when the loop encounters it
         return $this;
     }
     //Find all other blocks with that name
     foreach ($this->blocks as $block) {
         if ($block === $node || $block->name !== $node->name) {
             continue;
         }
         $mode = $block->mode;
         //detach from parent
         $block->parent->remove($block);
         switch ($mode) {
             default:
                 /** @noinspection PhpMissingBreakStatementInspection */
             /** @noinspection PhpMissingBreakStatementInspection */
             case 'replace':
                 $node->children = [];
                 //WANTED FALLTHROUGH!
             //WANTED FALLTHROUGH!
             case 'append':
                 //Append to master block
                 foreach ($block->children as $child) {
                     $block->remove($child);
                     $node->append($child);
                 }
                 break;
             case 'prepend':
                 $last = null;
                 foreach ($block->children as $child) {
                     $block->remove($child);
                     if (!$last) {
                         $node->prepend($child);
                         $last = $child;
                         continue;
                     }
                     $node->insertAfter($last, $child);
                     $last = $child;
                 }
                 break;
         }
         $block->mode = 'ignore';
     }
     return $this;
 }