trekel / src / php / Trekel / Node.php

<?php

abstract class Trekel_Node {


  protected $child = null;
  protected $identifier = null;
  protected $selector = null;

  public function setSelector ($selector) {
    $this->selector = $selector;
  }

  public function getSelector () {
    return $this->selector;
  }

  public function setIdentifier ($id) {
    $this->setSelector($id);
    $this->identifier = $id;
  }

  public function getIdentifier () {
    return $this->identifier;
  }

  public function setChild ($node) {
    $this->child = $node;
  }

  public function pushChild ($node) {
    if ($this->child) {
      $this->child->pushChild($node);
    } else {
      $this->setChild($node);
    }
  }

  public function getChild () {
    return $this->child;
  }

  public function next () {
    return $this->getChild();
  }

  abstract public function reduce ($node, $idx);

  private $matches = null;

  protected function initMatches () {
    $this->matches = new Trekel_List();
  }

  protected function matchType ($node) {
    $type = $this->getIdentifier();
    if ('*' == $type || $node instanceof $type) {
      $this->matches->append($node);
    }
  }

  protected function getMatches () {
    return $this->matches;
  }

  //protected function getChildren ($node) {
    //if (!$node) {
      //return array();
    //}
    //return array($node->getChild());
  //}

  protected function getParent ($node) {
    return $node->getParent();
  }


  private $queue;

  protected function initQueue ($node) {
    $this->queue = new Trekel_List();
    $this->enqueue($node);
  }

  protected function enqueue ($node) {
    if (is_array($node)) {
      $this->queue->appendAll($node);
    } else {
      $this->queue->append($node);
    }
  }

  protected function dequeue () {
    return $this->queue->next();
  }

} // end Trekel_Node
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.