@@ -356,6 +356,18 @@ private function quote($s)
356
356
return '\\Q ' .str_replace ('\\E ' , '\\E \\\\E \\Q ' , $ s ).'\\E ' ;
357
357
}
358
358
359
+ /**
360
+ * Converts a string into a regex that matches it at the beginning
361
+ *
362
+ * @param mixed $s The string or array being replaced.
363
+ *
364
+ * @return string Returns the string converted.
365
+ */
366
+ private function regexStartWith ($ s )
367
+ {
368
+ return '^ ' . $ this ->quote ($ s );
369
+ }
370
+
359
371
/**
360
372
* Add a constraint to the query that requires a particular key's value to
361
373
* start with the provided value.
@@ -367,7 +379,7 @@ private function quote($s)
367
379
*/
368
380
public function startsWith ($ key , $ value )
369
381
{
370
- $ this ->addCondition ($ key , '$regex ' , ' ^ ' . $ this ->quote ($ value ));
382
+ $ this ->addCondition ($ key , '$regex ' , $ this ->regexStartWith ($ value ));
371
383
372
384
return $ this ;
373
385
}
@@ -1197,6 +1209,25 @@ public function containsAll($key, $values)
1197
1209
return $ this ;
1198
1210
}
1199
1211
1212
+ /**
1213
+ * Add a constraint to the query that requires a particular key's value to
1214
+ * contain each one of the provided list of values starting with the given string.
1215
+ *
1216
+ * @param string $key The key to check. This key's value must be an array.
1217
+ * @param array $values The values that will match as starting string.
1218
+ *
1219
+ * @return ParseQuery Returns the query, so you can chain this call.
1220
+ */
1221
+ public function containsAllStartingWith ($ key , $ values )
1222
+ {
1223
+ $ opts = [];
1224
+ for ($ i = 0 ; $ i < count ($ values ); $ i += 1 ) {
1225
+ $ opts [] = ['$regex ' => $ this ->regexStartWith ($ values [$ i ])];
1226
+ }
1227
+
1228
+ return $ this ->containsAll ($ key , $ opts );
1229
+ }
1230
+
1200
1231
/**
1201
1232
* Add a constraint for finding objects that contain the given key.
1202
1233
*
0 commit comments