You are here

protected function QueryPathCssEventHandler::attrValMatches in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::attrValMatches()
  2. 7.2 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::attrValMatches()
2 calls to QueryPathCssEventHandler::attrValMatches()
QueryPathCssEventHandler::attribute in QueryPath/CssEventHandler.php
QueryPathCssEventHandler::attributeNS in QueryPath/CssEventHandler.php

File

QueryPath/CssEventHandler.php, line 916

Class

QueryPathCssEventHandler

Code

protected function attrValMatches($needle, $haystack, $operation) {
  if (strlen($haystack) < strlen($needle)) {
    return FALSE;
  }
  switch ($operation) {
    case CssEventHandler::isExactly:
      return $needle == $haystack;
    case CssEventHandler::containsWithSpace:
      return in_array($needle, explode(' ', $haystack));
    case CssEventHandler::containsWithHyphen:
      return in_array($needle, explode('-', $haystack));
    case CssEventHandler::containsInString:
      return strpos($haystack, $needle) !== FALSE;
    case CssEventHandler::beginsWith:
      return strpos($haystack, $needle) === 0;
    case CssEventHandler::endsWith:
      return preg_match('/' . $needle . '$/', $haystack) == 1;
  }
  return FALSE;
}