You are here

private function QueryPathCssEventHandler::getByPosition in QueryPath 7.3

Same name and namespace in other branches
  1. 6 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::getByPosition()
  2. 7.2 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::getByPosition()
1 call to QueryPathCssEventHandler::getByPosition()
QueryPathCssEventHandler::pseudoClass in QueryPath/CssEventHandler.php

File

QueryPath/CssEventHandler.php, line 506

Class

QueryPathCssEventHandler

Code

private function getByPosition($operator, $pos) {
  $matches = $this
    ->candidateList();
  $found = new SplObjectStorage();
  if ($matches
    ->count() == 0) {
    return;
  }
  switch ($operator) {
    case 'nth':
    case 'eq':
      if ($matches
        ->count() >= $pos) {
        foreach ($matches as $match) {
          if ($matches
            ->key() + 1 == $pos) {
            $found
              ->attach($match);
            break;
          }
        }
      }
      break;
    case 'first':
      if ($matches
        ->count() > 0) {
        $matches
          ->rewind();
        $found
          ->attach($matches
          ->current());
      }
      break;
    case 'last':
      if ($matches
        ->count() > 0) {
        foreach ($matches as $item) {
        }
        $found
          ->attach($item);
      }
      break;
    case 'lt':
      $i = 0;
      foreach ($matches as $item) {
        if (++$i < $pos) {
          $found
            ->attach($item);
        }
      }
      break;
    case 'gt':
      $i = 0;
      foreach ($matches as $item) {
        if (++$i > $pos) {
          $found
            ->attach($item);
        }
      }
      break;
  }
  $this->matches = $found;
}