/**
  * @return FunctionIndex
  */
 public function index()
 {
     $index = new FunctionIndex();
     $traverser = new NodeTraverser();
     $visitor = new BasicFunctionIndexerVisitor($this->file, $index);
     $traverser->addVisitor($visitor);
     $traverser->traverse($this->nodes->getArrayCopy());
     return $index;
 }
Example #2
0
 /**
  * @param Node
  * @param [int]
  * @return Node the given child
  */
 public function addChild(Node $node, $priority = NULL)
 {
     if ($node->parent) {
         throw new \Nette\InvalidStateException("The node is already bound to a parent.");
     }
     if ($node === $this) {
         throw new \Nette\InvalidStateException("The node can not be bound to itself.");
     }
     $node->parent = $this;
     $this->children->insert($node, array($priority, $this->nextChildrenNumber--));
     return $node;
 }
Example #3
0
 /**
  * Get the instance as an array.
  *
  * @return array
  */
 public function toArray()
 {
     return ['id' => $this->id, 'view' => $this->view, 'attributes' => $this->attributes, 'tree' => $this->toArrayTree(), 'items' => $this->items->values()->toArray()];
 }
Example #4
0
 /**
  * Replace each target node with the set of matched nodes.
  * @param Node|Node[]|NodeCollection $targets Targets to replace.
  * @return $this
  */
 public function replaceAll($targets)
 {
     if ($targets instanceof Node) {
         $targets->replaceWith($this->nodes);
     } elseif ($targets instanceof NodeCollection || is_array($targets)) {
         $first = TRUE;
         /** @var Node $target */
         foreach ($targets as $target) {
             $target->replaceWith($first ? $this->nodes : clone $this);
             $first = FALSE;
         }
     }
     return $this;
 }