Source

trekel / src / php / Trekel / Node / Selector / Adjacent.php

<?php

/**
 * Adjacent means "directly after the specified sibling
 * 
 * <div><a /><b /><i /></div>
 *
 * a + b  // matches one (b)
 * b + a  // matches none
 * b + i  // matches one (i)
 * * + *  // matches two (b, i)
 */
class Trekel_Node_Selector_Adjacent extends Trekel_Node_Selector {

  public function reduce ($node, $idx) {
    $this->initMatches();
    if ($parent = $node->getParent()) {
      $children = $parent->getChildren();
      $hash = spl_object_hash($node);
      while ($child = array_shift($children)) {
        if (spl_object_hash($child) == $hash) {
          break;
        }
      }
      $adj = array_shift($children);
      if ($adj) {
        $this->matchType($adj);
      }
    }
    return $this->getMatches();
  }

} // Trekel_Node_Selector_Adjacent