diff options
author | Bo Yang <teboring@google.com> | 2017-12-14 11:33:34 -0800 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2017-12-14 11:33:34 -0800 |
commit | 39159c89f1e6924c1b12a6f12478b6de199894f4 (patch) | |
tree | 69161fab51afe35514fe53c3143c8f4440fdde2d /php | |
parent | 1a549d9a902151e980bfa76093b3d82b7589e158 (diff) |
Accept DatetimeInterface in fromDatetime
Diffstat (limited to 'php')
-rw-r--r-- | php/ext/google/protobuf/message.c | 17 | ||||
-rw-r--r-- | php/ext/google/protobuf/protobuf.c | 9 |
2 files changed, 14 insertions, 12 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index df5eb408..8b7d57ad 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -1123,21 +1123,16 @@ PHP_METHOD(Timestamp, fromDateTime) { zval* datetime; zval member; - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "z", &datetime) == FAILURE) { - return; - } - - zend_class_entry* ce = Z_OBJCE_P(datetime); - PHP_PROTO_CE_DECLARE datetime_ce; - if (php_proto_zend_lookup_class("\\Datetime", 9, &datetime_ce) == - FAILURE) { + PHP_PROTO_CE_DECLARE date_interface_ce; + if (php_proto_zend_lookup_class("\\DatetimeInterface", 18, + &date_interface_ce) == FAILURE) { zend_error(E_ERROR, "Make sure date extension is enabled."); return; } - if (!instanceof_function(PHP_PROTO_CE_UNREF(datetime_ce), ce TSRMLS_CC)) { - zend_error(E_USER_ERROR, "Expect Datetime."); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &datetime, + date_interface_ce) == FAILURE) { + zend_error(E_USER_ERROR, "Expect DatetimeInterface."); return; } diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index 265d636e..daebb460 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -182,8 +182,15 @@ zend_function_entry protobuf_functions[] = { ZEND_FE_END }; +static const zend_module_dep protobuf_deps[] = { + ZEND_MOD_OPTIONAL("date") + ZEND_MOD_END +}; + zend_module_entry protobuf_module_entry = { - STANDARD_MODULE_HEADER, + STANDARD_MODULE_HEADER_EX, + NULL, + protobuf_deps, PHP_PROTOBUF_EXTNAME, // extension name protobuf_functions, // function list PHP_MINIT(protobuf), // process startup |