2
2
/**
3
3
* <class description>
4
4
* @author Alex Gorbylev <alex@gorbylev.ru>
5
- * @date 2012.03.30
5
+ * @tweaks Anton Gurov <trashmailbox@e1.ru>
6
+ * @date 2013.07.03
6
7
*/
7
8
final class NoSQLExpression implements LogicalObject, MappableObject {
8
9
@@ -60,9 +61,35 @@ public function __construct($unite = true) {
60
61
$ this ->unite = (bool )$ unite ;
61
62
}
62
63
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
+ }
63
90
/// field list
64
91
//@{
65
- /**
92
+ /**
66
93
* @param string $fieldName
67
94
* @return NoSQLExpression
68
95
*/
@@ -109,48 +136,48 @@ public function addNotEq($field, $value) {
109
136
}
110
137
111
138
public function addGt ($ field , $ value ) {
112
- Assert:: isInteger ($ value );
139
+ self :: assertIsComparable ($ value );
113
140
$ this ->conditions [] = array (
114
141
self ::C_TYPE => self ::EXP_GT ,
115
142
self ::C_FIELD => (string )$ field ,
116
- self ::C_VALUE => ( int ) $ value ,
143
+ self ::C_VALUE => $ value ,
117
144
);
118
145
return $ this ;
119
146
}
120
147
121
148
public function addGte ($ field , $ value ) {
122
- Assert:: isInteger ($ value );
149
+ self :: assertIsComparable ($ value );
123
150
$ this ->conditions [] = array (
124
151
self ::C_TYPE => self ::EXP_GTE ,
125
152
self ::C_FIELD => (string )$ field ,
126
- self ::C_VALUE => ( int ) $ value ,
153
+ self ::C_VALUE => $ value ,
127
154
);
128
155
return $ this ;
129
156
}
130
157
131
158
public function addLt ($ field , $ value ) {
132
- Assert:: isInteger ($ value );
159
+ self :: assertIsComparable ($ value );
133
160
$ this ->conditions [] = array (
134
161
self ::C_TYPE => self ::EXP_LT ,
135
162
self ::C_FIELD => (string )$ field ,
136
- self ::C_VALUE => ( int ) $ value ,
163
+ self ::C_VALUE => $ value ,
137
164
);
138
165
return $ this ;
139
166
}
140
167
141
168
public function addLte ($ field , $ value ) {
142
- Assert:: isInteger ($ value );
169
+ self :: assertIsComparable ($ value );
143
170
$ this ->conditions [] = array (
144
171
self ::C_TYPE => self ::EXP_LTE ,
145
172
self ::C_FIELD => (string )$ field ,
146
- self ::C_VALUE => ( int ) $ value ,
173
+ self ::C_VALUE => $ value ,
147
174
);
148
175
return $ this ;
149
176
}
150
177
151
178
public function addBetweenStrict ($ field , $ left , $ right ) {
152
- Assert:: isInteger ($ left );
153
- Assert:: isInteger ($ right );
179
+ self :: assertIsComparable ($ left );
180
+ self :: assertIsComparable ($ right );
154
181
$ this ->conditions [] = array (
155
182
self ::C_TYPE => self ::EXP_BTW_STR ,
156
183
self ::C_FIELD => (string )$ field ,
@@ -160,8 +187,8 @@ public function addBetweenStrict($field, $left, $right) {
160
187
}
161
188
162
189
public function addBetweenSoft ($ field , $ left , $ right ) {
163
- Assert:: isInteger ($ left );
164
- Assert:: isInteger ($ right );
190
+ self :: assertIsComparable ($ left );
191
+ self :: assertIsComparable ($ right );
165
192
$ this ->conditions [] = array (
166
193
self ::C_TYPE => self ::EXP_BTW_SFT ,
167
194
self ::C_FIELD => (string )$ field ,
0 commit comments