예제 #1
0
 /**
  * @param mixed|self $expression
  * @return mixed
  */
 protected function ensureArray($expression)
 {
     // Convert field names in expressions
     if (is_string($expression) && substr($expression, 0, 1) === '$') {
         return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
     }
     // Convert PHP types to MongoDB types for everything else
     return Type::convertPHPToDatabaseValue(parent::ensureArray($expression));
 }
예제 #2
0
 /**
  * Prepares the query criteria or new document object.
  *
  * PHP field names and types will be converted to those used by MongoDB.
  *
  * @param array $query
  * @return array
  */
 public function prepareQueryOrNewObj(array $query)
 {
     $preparedQuery = array();
     foreach ($query as $key => $value) {
         // Recursively prepare logical query clauses
         if (in_array($key, array('$and', '$or', '$nor')) && is_array($value)) {
             foreach ($value as $k2 => $v2) {
                 $preparedQuery[$key][$k2] = $this->prepareQueryOrNewObj($v2);
             }
             continue;
         }
         if (isset($key[0]) && $key[0] === '$' && is_array($value)) {
             $preparedQuery[$key] = $this->prepareQueryOrNewObj($value);
             continue;
         }
         list($key, $value) = $this->prepareQueryElement($key, $value, null, true);
         $preparedQuery[$key] = is_array($value) ? array_map('\\Doctrine\\ODM\\MongoDB\\Types\\Type::convertPHPToDatabaseValue', $value) : Type::convertPHPToDatabaseValue($value);
     }
     return $preparedQuery;
 }
예제 #3
0
 public function testConvertImmutableDate()
 {
     $date = new \DateTimeImmutable('now');
     $this->assertInstanceOf('\\MongoDate', Type::convertPHPToDatabaseValue($date));
 }