Skip to content

Commit 83e3df6

Browse files
author
justthefish
committed
Merge pull request #1 from AdOnWeb/nosql-fixes
fixes for mongodb
2 parents 57c0342 + 5cf7d97 commit 83e3df6

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

core/Logic/NoSQLExpression.class.php

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/**
33
* <class description>
44
* @author Alex Gorbylev <alex@gorbylev.ru>
5-
* @date 2012.03.30
5+
* @tweaks Anton Gurov <trashmailbox@e1.ru>
6+
* @date 2013.07.03
67
*/
78
final class NoSQLExpression implements LogicalObject, MappableObject {
89

@@ -60,9 +61,35 @@ public function __construct($unite = true) {
6061
$this->unite = (bool)$unite;
6162
}
6263

64+
/**
65+
* Замена Assert::checkInteger
66+
* @param $variable
67+
* @return bool
68+
*/
69+
public static function checkComparable($variable) {
70+
if (Assert::checkScalar($variable) || $variable instanceof MongoDate) {
71+
return true;
72+
} else {
73+
return false;
74+
}
75+
}
76+
77+
/**
78+
* Замена Assert::IsInteger
79+
* @param $variable
80+
* @param $message
81+
* @throws WrongArgumentException
82+
*/
83+
public static function assertIsComparable($variable, $message = null) {
84+
if (!self::checkComparable($variable)) {
85+
throw new WrongArgumentException(
86+
$message.', '.Assert::dumpArgument($variable)
87+
);
88+
}
89+
}
6390
/// field list
6491
//@{
65-
/**
92+
/**
6693
* @param string $fieldName
6794
* @return NoSQLExpression
6895
*/
@@ -109,48 +136,48 @@ public function addNotEq($field, $value) {
109136
}
110137

111138
public function addGt($field, $value) {
112-
Assert::isInteger($value);
139+
self::assertIsComparable($value);
113140
$this->conditions[] = array(
114141
self::C_TYPE => self::EXP_GT,
115142
self::C_FIELD => (string)$field,
116-
self::C_VALUE => (int)$value,
143+
self::C_VALUE => $value,
117144
);
118145
return $this;
119146
}
120147

121148
public function addGte($field, $value) {
122-
Assert::isInteger($value);
149+
self::assertIsComparable($value);
123150
$this->conditions[] = array(
124151
self::C_TYPE => self::EXP_GTE,
125152
self::C_FIELD => (string)$field,
126-
self::C_VALUE => (int)$value,
153+
self::C_VALUE => $value,
127154
);
128155
return $this;
129156
}
130157

131158
public function addLt($field, $value) {
132-
Assert::isInteger($value);
159+
self::assertIsComparable($value);
133160
$this->conditions[] = array(
134161
self::C_TYPE => self::EXP_LT,
135162
self::C_FIELD => (string)$field,
136-
self::C_VALUE => (int)$value,
163+
self::C_VALUE => $value,
137164
);
138165
return $this;
139166
}
140167

141168
public function addLte($field, $value) {
142-
Assert::isInteger($value);
169+
self::assertIsComparable($value);
143170
$this->conditions[] = array(
144171
self::C_TYPE => self::EXP_LTE,
145172
self::C_FIELD => (string)$field,
146-
self::C_VALUE => (int)$value,
173+
self::C_VALUE => $value,
147174
);
148175
return $this;
149176
}
150177

151178
public function addBetweenStrict($field, $left, $right) {
152-
Assert::isInteger($left);
153-
Assert::isInteger($right);
179+
self::assertIsComparable($left);
180+
self::assertIsComparable($right);
154181
$this->conditions[] = array(
155182
self::C_TYPE => self::EXP_BTW_STR,
156183
self::C_FIELD => (string)$field,
@@ -160,8 +187,8 @@ public function addBetweenStrict($field, $left, $right) {
160187
}
161188

162189
public function addBetweenSoft($field, $left, $right) {
163-
Assert::isInteger($left);
164-
Assert::isInteger($right);
190+
self::assertIsComparable($left);
191+
self::assertIsComparable($right);
165192
$this->conditions[] = array(
166193
self::C_TYPE => self::EXP_BTW_SFT,
167194
self::C_FIELD => (string)$field,

core/NoSQL/NoSqlResultList.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public function getCursor() {
3939
*/
4040
public function current() {
4141
$row = $this->getCursor()->current();
42-
$row['id'] = (string)$row['_id'];
42+
if ($row['_id'] instanceof MongoId) {
43+
$row['id'] = (string)$row['_id'];
44+
} else {
45+
$row['id'] = $row['_id'];
46+
}
4347
unset($row['_id']);
4448
return $this->result->getDao()->makeNoSqlObject($row);
4549
}

main/Base/LightMetaProperty.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ public function toValue(ProtoDAO $dao = null, $array, $prefix = null)
412412

413413
if($this->type == 'set') {
414414
// MongoDB driver compatibility
415+
415416
if( is_array($raw) ) {
416-
return $raw;
417+
418+
return $raw;
417419
} else {
418420
throw new WrongArgumentException('raw data is not array!');
419421
}

0 commit comments

Comments
 (0)