|
35 | 35 | #include <ext/standard/base64.h>
|
36 | 36 | #include <ext/standard/info.h>
|
37 | 37 | #include <Zend/zend_interfaces.h>
|
| 38 | +#include <Zend/zend_operators.h> |
38 | 39 | #include <ext/spl/spl_iterators.h>
|
39 | 40 | #include <ext/standard/php_var.h>
|
40 | 41 | #if PHP_VERSION_ID >= 70000
|
@@ -387,6 +388,26 @@ phongo_create_object_retval php_phongo_binary_create_object(zend_class_entry *cl
|
387 | 388 | #endif
|
388 | 389 | } /* }}} */
|
389 | 390 |
|
| 391 | +static int php_phongo_binary_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */ |
| 392 | +{ |
| 393 | + php_phongo_binary_t *intern1, *intern2; |
| 394 | + |
| 395 | + intern1 = Z_BINARY_OBJ_P(o1); |
| 396 | + intern2 = Z_BINARY_OBJ_P(o2); |
| 397 | + |
| 398 | + /* MongoDB compares binary types first by the data length, then by the type |
| 399 | + * byte, and finally by the binary data itself. */ |
| 400 | + if (intern1->data_len != intern2->data_len) { |
| 401 | + return intern1->data_len < intern2->data_len ? -1 : 1; |
| 402 | + } |
| 403 | + |
| 404 | + if (intern1->type != intern2->type) { |
| 405 | + return intern1->type < intern2->type ? -1 : 1; |
| 406 | + } |
| 407 | + |
| 408 | + return zend_binary_strcmp(intern1->data, intern1->data_len, intern2->data, intern2->data_len); |
| 409 | +} /* }}} */ |
| 410 | + |
390 | 411 | HashTable *php_phongo_binary_get_properties(zval *object TSRMLS_DC) /* {{{ */
|
391 | 412 | {
|
392 | 413 | php_phongo_binary_t *intern;
|
@@ -443,6 +464,7 @@ PHP_MINIT_FUNCTION(Binary)
|
443 | 464 | zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, zend_ce_serializable);
|
444 | 465 |
|
445 | 466 | memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
|
| 467 | + php_phongo_handler_binary.compare_objects = php_phongo_binary_compare_objects; |
446 | 468 | php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties;
|
447 | 469 | #if PHP_VERSION_ID >= 70000
|
448 | 470 | php_phongo_handler_binary.free_obj = php_phongo_binary_free_object;
|
|
0 commit comments