You are here

protected function QPACssEventHandler::descender in QueryPath 6

Same name and namespace in other branches
  1. 7.3 qpa/qpa.classes.inc \QPACssEventHandler::descender()
  2. 7.2 qpa/qpa.classes.inc \QPACssEventHandler::descender()

Search a nested array.

This will recurse through n-deep arrays, storing a collection of matches.

Parameters

$name: String name of the item to search for. If searching for an atribute, prepend this with '#'. If name = '*', any element name that does not begin with '#' will be matched.

$items: An associative array of items to seek.

$value: An (optional) value to search for. If this is specified, both name and value must be matched before an item is considered a match.

$matches: An array of matches. This is typically only used when recursing. Don't use it unless you know what you are doing.

1 call to QPACssEventHandler::descender()
QPACssEventHandler::descendList in qpa/qpa.classes.inc
Descend through a list and find matches.

File

qpa/qpa.classes.inc, line 116
qpa.classes

Class

QPACssEventHandler
qpa.classes

Code

protected function descender($name, $items, $value = NULL, &$matches = array(), $prefix = array()) {

  // XXX: this could be expanded to handle traversables.
  if (!is_array($items)) {
    return $matches;
  }
  foreach ($items as $n => $v) {
    if ($n == $name || $name == '*' && $n[0] != '#') {

      // If value is set, then we do a comparison
      if (isset($value)) {

        // If the comparison matches, add the item to matches.
        if ($value == $v) {
          $key = $prefix;
          $key[] = $name;
          $matches[] = $key;
        }
      }
      else {
        $key = $prefix;
        $key[] = $name;
        $matches[] = $key;
      }
    }
    if (is_array($v)) {

      // Recurse
      $base = $prefix;
      $base[] = $n;
      $this
        ->descender($name, $v, $value, $matches, $base);
    }
  }
  return $matches;
}