/**
  * This method checks the validity of a text-match.
  *
  * A single text-match should be specified as well as the specific property
  * or parameter we need to validate.
  *
  * @param VObject\Node|string $check Value to check against.
  * @param array $textMatch
  * @return bool
  */
 protected function validateTextMatch($check, array $textMatch)
 {
     if ($check instanceof VObject\Node) {
         $check = (string) $check;
     }
     $isMatching = \SabreForRainLoop\DAV\StringUtil::textMatch($check, $textMatch['value'], $textMatch['collation']);
     return $textMatch['negate-condition'] xor $isMatching;
 }
Ejemplo n.º 2
0
 /**
  * Validates if a text-filter can be applied to a specific property.
  *
  * @param array $texts
  * @param array $filters
  * @param string $test
  * @return bool
  */
 protected function validateTextMatches(array $texts, array $filters, $test)
 {
     foreach ($filters as $filter) {
         $success = false;
         foreach ($texts as $haystack) {
             $success = DAV\StringUtil::textMatch($haystack, $filter['value'], $filter['collation'], $filter['match-type']);
             // Breaking on the first match
             if ($success) {
                 break;
             }
         }
         if ($filter['negate-condition']) {
             $success = !$success;
         }
         if ($success && $test === 'anyof') {
             return true;
         }
         if (!$success && $test == 'allof') {
             return false;
         }
     }
     // If we got all the way here, it means we haven't been able to
     // determine early if the test failed or not.
     //
     // This implies for 'anyof' that the test failed, and for 'allof' that
     // we succeeded. Sounds weird, but makes sense.
     return $test === 'allof';
 }