Skip to content

Commit 4d07061

Browse files
committed
Merge pull request #500
2 parents f937228 + f943838 commit 4d07061

File tree

11 files changed

+57
-24
lines changed

11 files changed

+57
-24
lines changed

php_phongo.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ ZEND_DECLARE_MODULE_GLOBALS(mongodb)
7373
#endif
7474
#endif
7575

76+
/* Declare zend_class_entry dependencies, which are initialized in MINIT */
77+
zend_class_entry *php_phongo_date_immutable_ce;
78+
zend_class_entry *php_phongo_json_serializable_ce;
79+
7680
php_phongo_server_description_type_map_t
7781
php_phongo_server_description_type_map[PHONGO_SERVER_DESCRIPTION_TYPES] = {
7882
{ PHONGO_SERVER_UNKNOWN, "Unknown" },
@@ -1854,6 +1858,25 @@ PHP_GINIT_FUNCTION(mongodb)
18541858
}
18551859
/* }}} */
18561860

1861+
static zend_class_entry *php_phongo_fetch_internal_class(const char *class_name, size_t class_name_len TSRMLS_DC)
1862+
{
1863+
#if PHP_VERSION_ID >= 70000
1864+
zend_class_entry *pce;
1865+
1866+
if ((pce = zend_hash_str_find_ptr(CG(class_table), class_name, class_name_len))) {
1867+
return pce;
1868+
}
1869+
#else
1870+
zend_class_entry **pce;
1871+
1872+
if (zend_hash_find(CG(class_table), class_name, class_name_len + 1, (void **) &pce) == SUCCESS) {
1873+
return *pce;
1874+
}
1875+
#endif
1876+
1877+
return NULL;
1878+
}
1879+
18571880
/* {{{ PHP_MINIT_FUNCTION */
18581881
PHP_MINIT_FUNCTION(mongodb)
18591882
{
@@ -1886,6 +1909,25 @@ PHP_MINIT_FUNCTION(mongodb)
18861909
phongo_std_object_handlers.get_closure = NULL;
18871910
*/
18881911

1912+
/* Initialize zend_class_entry dependencies.
1913+
*
1914+
* Although DateTimeImmutable was introduced in PHP 5.5.0,
1915+
* php_date_get_immutable_ce() is not available in PHP versions before
1916+
* 5.5.24 and 5.6.8.
1917+
*
1918+
* Although JsonSerializable was introduced in PHP 5.4.0,
1919+
* php_json_serializable_ce is not exported in PHP versions before 5.4.26
1920+
* and 5.5.10. For later PHP versions, looking up the class manually also
1921+
* helps with distros that disable LTDL_LAZY for dlopen() (e.g. Fedora).
1922+
*/
1923+
php_phongo_date_immutable_ce = php_phongo_fetch_internal_class(ZEND_STRL("datetimeimmutable") TSRMLS_CC);
1924+
php_phongo_json_serializable_ce = php_phongo_fetch_internal_class(ZEND_STRL("jsonserializable") TSRMLS_CC);
1925+
1926+
if (php_phongo_json_serializable_ce == NULL) {
1927+
zend_error(E_ERROR, "JsonSerializable class is not defined. Please ensure that the 'json' module is loaded before the 'mongodb' module.");
1928+
return FAILURE;
1929+
}
1930+
18891931
PHP_MINIT(bson)(INIT_FUNC_ARGS_PASSTHRU);
18901932

18911933
PHP_MINIT(Type)(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_classes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#include "php_phongo_structs.h"
2121

22+
/* Export zend_class_entry dependencies, which are initialized in MINIT */
23+
extern zend_class_entry *php_phongo_date_immutable_ce;
24+
extern zend_class_entry *php_phongo_json_serializable_ce;
25+
2226
#if PHP_VERSION_ID >= 70000
2327

2428
static inline php_phongo_bulkwrite_t* php_bulkwrite_fetch_object(zend_object *obj) {

src/BSON/Binary.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/base64.h>
3029
#include <ext/standard/info.h>
3130
#include <Zend/zend_interfaces.h>
@@ -453,7 +452,7 @@ PHP_MINIT_FUNCTION(Binary)
453452
php_phongo_binary_ce->create_object = php_phongo_binary_create_object;
454453
PHONGO_CE_FINAL(php_phongo_binary_ce);
455454

456-
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_json_serializable_ce);
455+
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
457456
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_phongo_type_ce);
458457
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, zend_ce_serializable);
459458

src/BSON/Decimal128.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -368,7 +367,7 @@ PHP_MINIT_FUNCTION(Decimal128)
368367
php_phongo_decimal128_ce->create_object = php_phongo_decimal128_create_object;
369368
PHONGO_CE_FINAL(php_phongo_decimal128_ce);
370369

371-
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, php_json_serializable_ce);
370+
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
372371
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, php_phongo_type_ce);
373372
zend_class_implements(php_phongo_decimal128_ce TSRMLS_CC, 1, zend_ce_serializable);
374373

src/BSON/Javascript.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -533,7 +532,7 @@ PHP_MINIT_FUNCTION(Javascript)
533532
php_phongo_javascript_ce->create_object = php_phongo_javascript_create_object;
534533
PHONGO_CE_FINAL(php_phongo_javascript_ce);
535534

536-
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, php_json_serializable_ce);
535+
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
537536
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, php_phongo_type_ce);
538537
zend_class_implements(php_phongo_javascript_ce TSRMLS_CC, 1, zend_ce_serializable);
539538

src/BSON/MaxKey.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -166,7 +165,7 @@ PHP_MINIT_FUNCTION(MaxKey)
166165
php_phongo_maxkey_ce->create_object = php_phongo_maxkey_create_object;
167166
PHONGO_CE_FINAL(php_phongo_maxkey_ce);
168167

169-
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_json_serializable_ce);
168+
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
170169
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
171170
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, zend_ce_serializable);
172171

src/BSON/MinKey.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -167,7 +166,7 @@ PHP_MINIT_FUNCTION(MinKey)
167166
php_phongo_minkey_ce->create_object = php_phongo_minkey_create_object;
168167
PHONGO_CE_FINAL(php_phongo_minkey_ce);
169168

170-
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_json_serializable_ce);
169+
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
171170
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
172171
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, zend_ce_serializable);
173172

src/BSON/ObjectID.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -418,7 +417,7 @@ PHP_MINIT_FUNCTION(ObjectID)
418417
php_phongo_objectid_ce->create_object = php_phongo_objectid_create_object;
419418
PHONGO_CE_FINAL(php_phongo_objectid_ce);
420419

421-
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_json_serializable_ce);
420+
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
422421
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_type_ce);
423422
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, zend_ce_serializable);
424423

src/BSON/Regex.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -467,7 +466,7 @@ PHP_MINIT_FUNCTION(Regex)
467466

468467
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_phongo_type_ce);
469468
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, zend_ce_serializable);
470-
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_json_serializable_ce);
469+
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
471470

472471
memcpy(&php_phongo_handler_regex, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
473472
php_phongo_handler_regex.compare_objects = php_phongo_regex_compare_objects;

src/BSON/Timestamp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
/* PHP Core stuff */
2626
#include <php.h>
2727
#include <php_ini.h>
28-
#include <ext/json/php_json.h>
2928
#include <ext/standard/info.h>
3029
#include <Zend/zend_interfaces.h>
3130
#include <ext/spl/spl_iterators.h>
@@ -498,7 +497,7 @@ PHP_MINIT_FUNCTION(Timestamp)
498497
php_phongo_timestamp_ce->create_object = php_phongo_timestamp_create_object;
499498
PHONGO_CE_FINAL(php_phongo_timestamp_ce);
500499

501-
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_json_serializable_ce);
500+
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_phongo_json_serializable_ce);
502501
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_phongo_type_ce);
503502
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, zend_ce_serializable);
504503

0 commit comments

Comments
 (0)