File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -402,6 +402,24 @@ phongo_create_object_retval php_phongo_regex_create_object(zend_class_entry *cla
402402#endif
403403} /* }}} */
404404
405+ static int php_phongo_regex_compare_objects (zval * o1 , zval * o2 TSRMLS_DC ) /* {{{ */
406+ {
407+ php_phongo_regex_t * intern1 , * intern2 ;
408+ int retval ;
409+
410+ intern1 = Z_REGEX_OBJ_P (o1 );
411+ intern2 = Z_REGEX_OBJ_P (o2 );
412+
413+ /* MongoDB compares the pattern string before the flags. */
414+ retval = strcmp (intern1 -> pattern , intern2 -> pattern );
415+
416+ if (retval != 0 ) {
417+ return retval ;
418+ }
419+
420+ return strcmp (intern1 -> flags , intern2 -> flags );
421+ } /* }}} */
422+
405423HashTable * php_phongo_regex_get_properties (zval * object TSRMLS_DC ) /* {{{ */
406424{
407425 php_phongo_regex_t * intern ;
@@ -458,6 +476,7 @@ PHP_MINIT_FUNCTION(Regex)
458476 zend_class_implements (php_phongo_regex_ce TSRMLS_CC , 1 , php_json_serializable_ce );
459477
460478 memcpy (& php_phongo_handler_regex , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
479+ php_phongo_handler_regex .compare_objects = php_phongo_regex_compare_objects ;
461480 php_phongo_handler_regex .get_properties = php_phongo_regex_get_properties ;
462481#if PHP_VERSION_ID >= 70000
463482 php_phongo_handler_regex .free_obj = php_phongo_regex_free_object ;
Original file line number Diff line number Diff line change 1+ --TEST--
2+ MongoDB\BSON\Regex comparisons (without flags)
3+ --FILE--
4+ <?php
5+
6+ var_dump (new MongoDB \BSON \Regex ('regexp ' ) == new MongoDB \BSON \Regex ('regexp ' ));
7+ var_dump (new MongoDB \BSON \Regex ('regexp ' ) < new MongoDB \BSON \Regex ('regexp ' ));
8+ var_dump (new MongoDB \BSON \Regex ('regexp ' ) > new MongoDB \BSON \Regex ('regexp ' ));
9+
10+ var_dump (new MongoDB \BSON \Regex ('regexp ' ) < new MongoDB \BSON \Regex ('regexr ' ));
11+ var_dump (new MongoDB \BSON \Regex ('regexp ' ) > new MongoDB \BSON \Regex ('regexo ' ));
12+
13+ ?>
14+ ===DONE===
15+ <?php exit (0 ); ?>
16+ --EXPECTF--
17+ bool(true)
18+ bool(false)
19+ bool(false)
20+ bool(true)
21+ bool(true)
22+ ===DONE===
Original file line number Diff line number Diff line change 1+ --TEST--
2+ MongoDB\BSON\Regex comparisons (with flags)
3+ --FILE--
4+ <?php
5+
6+ var_dump (new MongoDB \BSON \Regex ('regexp ' , 'm ' ) == new MongoDB \BSON \Regex ('regexp ' , 'm ' ));
7+ var_dump (new MongoDB \BSON \Regex ('regexp ' , 'm ' ) < new MongoDB \BSON \Regex ('regexp ' , 'm ' ));
8+ var_dump (new MongoDB \BSON \Regex ('regexp ' , 'm ' ) > new MongoDB \BSON \Regex ('regexp ' , 'm ' ));
9+
10+ var_dump (new MongoDB \BSON \Regex ('regexp ' , 'm ' ) < new MongoDB \BSON \Regex ('regexp ' , 'x ' ));
11+ var_dump (new MongoDB \BSON \Regex ('regexp ' , 'm ' ) > new MongoDB \BSON \Regex ('regexp ' , 'i ' ));
12+ var_dump (new MongoDB \BSON \Regex ('regexp ' , 'm ' ) > new MongoDB \BSON \Regex ('regexp ' ));
13+
14+ ?>
15+ ===DONE===
16+ <?php exit (0 ); ?>
17+ --EXPECTF--
18+ bool(true)
19+ bool(false)
20+ bool(false)
21+ bool(true)
22+ bool(true)
23+ bool(true)
24+ ===DONE===
You can’t perform that action at this time.
0 commit comments