From 9f6aceaa8ce8250d9e36225180c218035bd49fe9 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 12 Dec 2017 12:06:51 -0800 Subject: Add PROTOBUF_ENABLE_TIMESTAMP to let user decide whether timestamp util can be used at install time. --- php/ext/google/protobuf/message.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'php/ext/google') diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index b14c1f0c..70080a3b 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -29,9 +29,12 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include #include +#ifdef PROTOBUF_ENABLE_TIMESTAMP +#include +#endif + #include "protobuf.h" #include "utf8.h" @@ -1121,6 +1124,7 @@ PHP_PROTO_FIELD_ACCESSORS(Timestamp, timestamp, Seconds, "seconds") PHP_PROTO_FIELD_ACCESSORS(Timestamp, timestamp, Nanos, "nanos") PHP_METHOD(Timestamp, fromDateTime) { +#ifdef PROTOBUF_ENABLE_TIMESTAMP zval* datetime; zval member; @@ -1149,9 +1153,13 @@ PHP_METHOD(Timestamp, fromDateTime) { storage = message_data(self); memory = slot_memory(self->descriptor->layout, storage, field); *(int32_t*)memory = 0; +#else + zend_error(E_USER_ERROR, "fromDateTime needs date extension."); +#endif } PHP_METHOD(Timestamp, toDateTime) { +#ifdef PROTOBUF_ENABLE_TIMESTAMP zval datetime; php_date_instantiate(php_date_get_date_ce(), &datetime TSRMLS_CC); php_date_obj* dateobj = UNBOX(php_date_obj, &datetime); @@ -1184,6 +1192,9 @@ PHP_METHOD(Timestamp, toDateTime) { zval* datetime_ptr = &datetime; PHP_PROTO_RETVAL_ZVAL(datetime_ptr); +#else + zend_error(E_USER_ERROR, "toDateTime needs date extension."); +#endif } // ----------------------------------------------------------------------------- -- cgit v1.2.3