コード例 #1
0
ファイル: CriteriaMatcher.php プロジェクト: michaldudek/knit
 /**
  * Checks if the object's property matches the given criterium.
  *
  * @param array         $object    Object (transformed to array) to match against.
  * @param PropertyValue $criterium Single criterium.
  *
  * @return bool
  *
  * @throws InvalidOperatorException When an unsupported operator was used.
  */
 private function matchesProperty(array $object, PropertyValue $criterium)
 {
     $property = $criterium->getProperty();
     $operator = $criterium->getOperator();
     $value = $criterium->getValue();
     if (!isset(self::$operatorExpressionMap[$operator]) || !method_exists($this, self::$operatorExpressionMap[$operator])) {
         throw new InvalidOperatorException(sprintf('Memory CriteriaMatcher cannot handle operator %s', trim($operator, '_')));
     }
     $method = self::$operatorExpressionMap[$operator];
     return $this->{$method}($object, $property, $value);
 }
コード例 #2
0
ファイル: CriteriaParser.php プロジェクト: michaldudek/knit
 /**
  * Parses a single criterium.
  *
  * @param PropertyValue $criterium    Single criterium.
  * @param array         $result       Result of parsing criteria so far.
  * @param boolean       $asCollection [optional] Should this criteria be parsed as a collection?
  *                                    Required for OR logic. For internal use. Default: `false`.
  *
  * @return array
  */
 private function parseCriterium(PropertyValue $criterium, array $result, $asCollection = false)
 {
     $property = $criterium->getProperty();
     $operator = $criterium->getOperator();
     $value = $criterium->getValue();
     // to ensure compatibility with other stores, we treat `_id` and `id` the same
     if ($property === 'id') {
         $property = '_id';
     }
     // convert the `_id` property to MongoID
     if ($property === '_id') {
         $value = $this->convertToMongoId($value);
     }
     // merge operator with the value according to Mongo Api
     $value = $this->parseOperator($property, $operator, $value);
     if ($asCollection) {
         $result[] = [$property => $value];
     } else {
         $result[$property] = isset($result[$property]) ? $this->mergeCriteria($result[$property], $value, $operator) : $value;
     }
     return $result;
 }
コード例 #3
0
ファイル: CriteriaParser.php プロジェクト: michaldudek/knit
 /**
  * Creates a single expression based on the passed criterium and sets appropriate parameters
  * in the query builder.
  *
  * @param QueryBuilder  $queryBuilder Query builder to be configured.
  * @param PropertyValue $criterium    Single criterium.
  *
  * @return string
  *
  * @throws InvalidOperatorException When an unsupported operator was used.
  */
 private function createExpression(QueryBuilder $queryBuilder, PropertyValue $criterium)
 {
     $property = $criterium->getProperty();
     $operator = $criterium->getOperator();
     $value = $criterium->getValue();
     if (!isset(self::$operatorExpressionMap[$operator]) || !method_exists($this, self::$operatorExpressionMap[$operator])) {
         throw new InvalidOperatorException(sprintf('DoctrineDBAL cannot handle operator %s', trim($operator, '_')));
     }
     $method = self::$operatorExpressionMap[$operator];
     return $this->{$method}($queryBuilder, $property, $value);
 }