Beispiel #1
0
 /**
  * Prepares a query expression.
  *
  * @param array|object  $expression
  * @param ClassMetadata $class
  * @return array
  */
 private function prepareQueryExpression($expression, $class)
 {
     foreach ($expression as $k => $v) {
         // Ignore query operators whose arguments need no type conversion
         if (in_array($k, array('$exists', '$type', '$mod', '$size'))) {
             continue;
         }
         // Process query operators whose argument arrays need type conversion
         if (in_array($k, array('$in', '$nin', '$all')) && is_array($v)) {
             foreach ($v as $k2 => $v2) {
                 $expression[$k][$k2] = $class->getDatabaseIdentifierValue($v2);
             }
             continue;
         }
         // Recursively process expressions within a $not operator
         if ($k === '$not' && is_array($v)) {
             $expression[$k] = $this->prepareQueryExpression($v, $class);
             continue;
         }
         $expression[$k] = $class->getDatabaseIdentifierValue($v);
     }
     return $expression;
 }
Beispiel #2
0
 /**
  * INTERNAL:
  * Tries to get a document by its identifier hash. If no document is found
  * for the given hash, FALSE is returned.
  *
  * @ignore
  * @param mixed         $id    Document identifier
  * @param ClassMetadata $class Document class
  * @return mixed The found document or FALSE.
  * @throws InvalidArgumentException if the class does not have an identifier
  */
 public function tryGetById($id, ClassMetadata $class)
 {
     if (!$class->identifier) {
         throw new \InvalidArgumentException(sprintf('Class "%s" does not have an identifier', $class->name));
     }
     $serializedId = serialize($class->getDatabaseIdentifierValue($id));
     return isset($this->identityMap[$class->name][$serializedId]) ? $this->identityMap[$class->name][$serializedId] : false;
 }