From 5cf7d97d0692df13b314ef33a45b3fce365f5f06 Mon Sep 17 00:00:00 2001 From: thefish Date: Wed, 3 Jul 2013 17:32:35 +0400 Subject: [PATCH] fixes --- core/Logic/NoSQLExpression.class.php | 55 ++++++++++++++++++++------- core/NoSQL/NoSqlResultList.class.php | 6 ++- main/Base/LightMetaProperty.class.php | 4 +- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/core/Logic/NoSQLExpression.class.php b/core/Logic/NoSQLExpression.class.php index 0cd11d2927..e7bc1b5793 100755 --- a/core/Logic/NoSQLExpression.class.php +++ b/core/Logic/NoSQLExpression.class.php @@ -2,7 +2,8 @@ /** * * @author Alex Gorbylev - * @date 2012.03.30 + * @tweaks Anton Gurov + * @date 2013.07.03 */ final class NoSQLExpression implements LogicalObject, MappableObject { @@ -60,9 +61,35 @@ public function __construct($unite = true) { $this->unite = (bool)$unite; } + /** + * Замена Assert::checkInteger + * @param $variable + * @return bool + */ + public static function checkComparable($variable) { + if (Assert::checkScalar($variable) || $variable instanceof MongoDate) { + return true; + } else { + return false; + } + } + + /** + * Замена Assert::IsInteger + * @param $variable + * @param $message + * @throws WrongArgumentException + */ + public static function assertIsComparable($variable, $message = null) { + if (!self::checkComparable($variable)) { + throw new WrongArgumentException( + $message.', '.Assert::dumpArgument($variable) + ); + } + } /// field list //@{ - /** + /** * @param string $fieldName * @return NoSQLExpression */ @@ -109,48 +136,48 @@ public function addNotEq($field, $value) { } public function addGt($field, $value) { - Assert::isInteger($value); + self::assertIsComparable($value); $this->conditions[] = array( self::C_TYPE => self::EXP_GT, self::C_FIELD => (string)$field, - self::C_VALUE => (int)$value, + self::C_VALUE => $value, ); return $this; } public function addGte($field, $value) { - Assert::isInteger($value); + self::assertIsComparable($value); $this->conditions[] = array( self::C_TYPE => self::EXP_GTE, self::C_FIELD => (string)$field, - self::C_VALUE => (int)$value, + self::C_VALUE => $value, ); return $this; } public function addLt($field, $value) { - Assert::isInteger($value); + self::assertIsComparable($value); $this->conditions[] = array( self::C_TYPE => self::EXP_LT, self::C_FIELD => (string)$field, - self::C_VALUE => (int)$value, + self::C_VALUE => $value, ); return $this; } public function addLte($field, $value) { - Assert::isInteger($value); + self::assertIsComparable($value); $this->conditions[] = array( self::C_TYPE => self::EXP_LTE, self::C_FIELD => (string)$field, - self::C_VALUE => (int)$value, + self::C_VALUE => $value, ); return $this; } public function addBetweenStrict($field, $left, $right) { - Assert::isInteger($left); - Assert::isInteger($right); + self::assertIsComparable($left); + self::assertIsComparable($right); $this->conditions[] = array( self::C_TYPE => self::EXP_BTW_STR, self::C_FIELD => (string)$field, @@ -160,8 +187,8 @@ public function addBetweenStrict($field, $left, $right) { } public function addBetweenSoft($field, $left, $right) { - Assert::isInteger($left); - Assert::isInteger($right); + self::assertIsComparable($left); + self::assertIsComparable($right); $this->conditions[] = array( self::C_TYPE => self::EXP_BTW_SFT, self::C_FIELD => (string)$field, diff --git a/core/NoSQL/NoSqlResultList.class.php b/core/NoSQL/NoSqlResultList.class.php index dc967d842e..c2a965301a 100644 --- a/core/NoSQL/NoSqlResultList.class.php +++ b/core/NoSQL/NoSqlResultList.class.php @@ -39,7 +39,11 @@ public function getCursor() { */ public function current() { $row = $this->getCursor()->current(); - $row['id'] = (string)$row['_id']; + if ($row['_id'] instanceof MongoId) { + $row['id'] = (string)$row['_id']; + } else { + $row['id'] = $row['_id']; + } unset($row['_id']); return $this->result->getDao()->makeNoSqlObject($row); } diff --git a/main/Base/LightMetaProperty.class.php b/main/Base/LightMetaProperty.class.php index 2487f98413..ca27b06f30 100755 --- a/main/Base/LightMetaProperty.class.php +++ b/main/Base/LightMetaProperty.class.php @@ -412,8 +412,10 @@ public function toValue(ProtoDAO $dao = null, $array, $prefix = null) if($this->type == 'set') { // MongoDB driver compatibility + if( is_array($raw) ) { - return $raw; + + return $raw; } else { throw new WrongArgumentException('raw data is not array!'); }