You are here

public function QueryPath::filterCallback in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/QueryPath.php \QueryPath::filterCallback()
  2. 7.2 QueryPath/QueryPath.php \QueryPath::filterCallback()

File

QueryPath/QueryPath.php, line 502

Class

QueryPath

Code

public function filterCallback($callback) {
  $found = new SplObjectStorage();
  $i = 0;
  if (is_callable($callback)) {
    foreach ($this->matches as $item) {
      if (call_user_func($callback, $i++, $item) !== FALSE) {
        $found
          ->attach($item);
      }
    }
  }
  else {
    throw new QueryPathException('The specified callback is not callable.');
  }
  $this
    ->setMatches($found);
  return $this;
}