diff options
Diffstat (limited to 'ext/date/php_date.c')
| -rw-r--r-- | ext/date/php_date.c | 123 |
1 files changed, 26 insertions, 97 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 5c6825e50f..67a9d66f63 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -76,97 +76,6 @@ PHPAPI time_t php_time() #include "php_date_arginfo.h" -static const zend_function_entry date_funcs_interface[] = { - PHP_ABSTRACT_ME(DateTimeInterface, format, arginfo_class_DateTimeInterface_format) - PHP_ABSTRACT_ME(DateTimeInterface, getTimezone, arginfo_class_DateTimeInterface_getTimezone) - PHP_ABSTRACT_ME(DateTimeInterface, getOffset, arginfo_class_DateTimeInterface_getOffset) - PHP_ABSTRACT_ME(DateTimeInterface, getTimestamp, arginfo_class_DateTimeInterface_getTimestamp) - PHP_ABSTRACT_ME(DateTimeInterface, diff, arginfo_class_DateTimeInterface_diff) - PHP_ABSTRACT_ME(DateTimeInterface, __wakeup, arginfo_class_DateTimeInterface___wakeup) - PHP_FE_END -}; - -static const zend_function_entry date_funcs_date[] = { - PHP_ME(DateTime, __construct, arginfo_class_DateTime___construct, ZEND_ACC_PUBLIC) - PHP_ME(DateTime, __wakeup, arginfo_class_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC) - PHP_ME(DateTime, __set_state, arginfo_class_DateTime___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(DateTime, createFromImmutable, arginfo_class_DateTime_createFromImmutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(DateTime, createFromInterface, arginfo_class_DateTime_createFromInterface, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(createFromFormat, date_create_from_format, arginfo_class_DateTime_createFromFormat, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(getLastErrors, date_get_last_errors, arginfo_class_DateTime_getLastErrors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(format, date_format, arginfo_class_DateTimeInterface_format, 0) - PHP_ME_MAPPING(modify, date_modify, arginfo_class_DateTime_modify, 0) - PHP_ME_MAPPING(add, date_add, arginfo_class_DateTime_add, 0) - PHP_ME_MAPPING(sub, date_sub, arginfo_class_DateTime_sub, 0) - PHP_ME_MAPPING(getTimezone, date_timezone_get, arginfo_class_DateTimeInterface_getTimezone, 0) - PHP_ME_MAPPING(setTimezone, date_timezone_set, arginfo_class_DateTime_setTimezone, 0) - PHP_ME_MAPPING(getOffset, date_offset_get, arginfo_class_DateTimeInterface_getOffset, 0) - PHP_ME_MAPPING(setTime, date_time_set, arginfo_class_DateTime_setTime, 0) - PHP_ME_MAPPING(setDate, date_date_set, arginfo_class_DateTime_setDate, 0) - PHP_ME_MAPPING(setISODate, date_isodate_set, arginfo_class_DateTime_setISODate, 0) - PHP_ME_MAPPING(setTimestamp, date_timestamp_set, arginfo_class_DateTime_setTimestamp, 0) - PHP_ME_MAPPING(getTimestamp, date_timestamp_get, arginfo_class_DateTimeInterface_getTimestamp, 0) - PHP_ME_MAPPING(diff, date_diff, arginfo_class_DateTimeInterface_diff, 0) - PHP_FE_END -}; - -static const zend_function_entry date_funcs_immutable[] = { - PHP_ME(DateTimeImmutable, __construct, arginfo_class_DateTimeImmutable___construct, ZEND_ACC_PUBLIC) - PHP_ME(DateTime, __wakeup, arginfo_class_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC) - PHP_ME(DateTimeImmutable, __set_state, arginfo_class_DateTimeImmutable___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(createFromFormat, date_create_immutable_from_format, arginfo_class_DateTimeImmutable_createFromFormat, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(getLastErrors, date_get_last_errors, arginfo_class_DateTimeImmutable_getLastErrors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(format, date_format, arginfo_class_DateTimeInterface_format, 0) - PHP_ME_MAPPING(getTimezone, date_timezone_get, arginfo_class_DateTimeInterface_getTimezone, 0) - PHP_ME_MAPPING(getOffset, date_offset_get, arginfo_class_DateTimeInterface_getOffset, 0) - PHP_ME_MAPPING(getTimestamp, date_timestamp_get, arginfo_class_DateTimeInterface_getTimestamp, 0) - PHP_ME_MAPPING(diff, date_diff, arginfo_class_DateTimeInterface_diff, 0) - PHP_ME(DateTimeImmutable, modify, arginfo_class_DateTimeImmutable_modify, 0) - PHP_ME(DateTimeImmutable, add, arginfo_class_DateTimeImmutable_add, 0) - PHP_ME(DateTimeImmutable, sub, arginfo_class_DateTimeImmutable_sub, 0) - PHP_ME(DateTimeImmutable, setTimezone, arginfo_class_DateTimeImmutable_setTimezone, 0) - PHP_ME(DateTimeImmutable, setTime, arginfo_class_DateTimeImmutable_setTime, 0) - PHP_ME(DateTimeImmutable, setDate, arginfo_class_DateTimeImmutable_setDate, 0) - PHP_ME(DateTimeImmutable, setISODate, arginfo_class_DateTimeImmutable_setISODate, 0) - PHP_ME(DateTimeImmutable, setTimestamp, arginfo_class_DateTimeImmutable_setTimestamp, 0) - PHP_ME(DateTimeImmutable, createFromMutable, arginfo_class_DateTimeImmutable_createFromMutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(DateTimeImmutable, createFromInterface, arginfo_class_DateTimeImmutable_createFromInterface, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_FE_END -}; - -static const zend_function_entry date_funcs_timezone[] = { - PHP_ME(DateTimeZone, __construct, arginfo_class_DateTimeZone___construct, ZEND_ACC_PUBLIC) - PHP_ME(DateTimeZone, __wakeup, arginfo_class_DateTimeZone___wakeup, ZEND_ACC_PUBLIC) - PHP_ME(DateTimeZone, __set_state, arginfo_class_DateTimeZone___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(getName, timezone_name_get, arginfo_class_DateTimeZone_getName, 0) - PHP_ME_MAPPING(getOffset, timezone_offset_get, arginfo_class_DateTimeZone_getOffset, 0) - PHP_ME_MAPPING(getTransitions, timezone_transitions_get, arginfo_class_DateTimeZone_getTransitions, 0) - PHP_ME_MAPPING(getLocation, timezone_location_get, arginfo_class_DateTimeZone_getLocation, 0) - PHP_ME_MAPPING(listAbbreviations, timezone_abbreviations_list, arginfo_class_DateTimeZone_listAbbreviations, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(listIdentifiers, timezone_identifiers_list, arginfo_class_DateTimeZone_listIdentifiers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_FE_END -}; - -static const zend_function_entry date_funcs_interval[] = { - PHP_ME(DateInterval, __construct, arginfo_class_DateInterval___construct, ZEND_ACC_PUBLIC) - PHP_ME(DateInterval, __wakeup, arginfo_class_DateInterval___wakeup, ZEND_ACC_PUBLIC) - PHP_ME(DateInterval, __set_state, arginfo_class_DateInterval___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME_MAPPING(format, date_interval_format, arginfo_class_DateInterval_format, 0) - PHP_ME_MAPPING(createFromDateString, date_interval_create_from_date_string, arginfo_class_DateInterval_createFromDateString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_FE_END -}; - -static const zend_function_entry date_funcs_period[] = { - PHP_ME(DatePeriod, __construct, arginfo_class_DatePeriod___construct, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, __wakeup, arginfo_class_DatePeriod___wakeup, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, __set_state, arginfo_class_DatePeriod___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(DatePeriod, getStartDate, arginfo_class_DatePeriod_getStartDate, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, getEndDate, arginfo_class_DatePeriod_getEndDate, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, getDateInterval, arginfo_class_DatePeriod_getDateInterval, ZEND_ACC_PUBLIC) - PHP_ME(DatePeriod, getRecurrences, arginfo_class_DatePeriod_getRecurrences, ZEND_ACC_PUBLIC) - PHP_FE_END -}; - static char* guess_timezone(const timelib_tzdb *tzdb); static void date_register_classes(void); /* }}} */ @@ -1681,7 +1590,7 @@ static void date_register_classes(void) /* {{{ */ { zend_class_entry ce_date, ce_immutable, ce_timezone, ce_interval, ce_period, ce_interface; - INIT_CLASS_ENTRY(ce_interface, "DateTimeInterface", date_funcs_interface); + INIT_CLASS_ENTRY(ce_interface, "DateTimeInterface", class_DateTimeInterface_methods); date_ce_interface = zend_register_internal_interface(&ce_interface); date_ce_interface->interface_gets_implemented = implement_date_interface_handler; @@ -1702,7 +1611,7 @@ static void date_register_classes(void) /* {{{ */ REGISTER_DATE_INTERFACE_CONST_STRING("RSS", DATE_FORMAT_RFC1123); REGISTER_DATE_INTERFACE_CONST_STRING("W3C", DATE_FORMAT_RFC3339); - INIT_CLASS_ENTRY(ce_date, "DateTime", date_funcs_date); + INIT_CLASS_ENTRY(ce_date, "DateTime", class_DateTime_methods); ce_date.create_object = date_object_new_date; date_ce_date = zend_register_internal_class_ex(&ce_date, NULL); memcpy(&date_object_handlers_date, &std_object_handlers, sizeof(zend_object_handlers)); @@ -1714,7 +1623,7 @@ static void date_register_classes(void) /* {{{ */ date_object_handlers_date.get_gc = date_object_get_gc; zend_class_implements(date_ce_date, 1, date_ce_interface); - INIT_CLASS_ENTRY(ce_immutable, "DateTimeImmutable", date_funcs_immutable); + INIT_CLASS_ENTRY(ce_immutable, "DateTimeImmutable", class_DateTimeImmutable_methods); ce_immutable.create_object = date_object_new_date; date_ce_immutable = zend_register_internal_class_ex(&ce_immutable, NULL); memcpy(&date_object_handlers_immutable, &std_object_handlers, sizeof(zend_object_handlers)); @@ -1724,7 +1633,7 @@ static void date_register_classes(void) /* {{{ */ date_object_handlers_immutable.get_gc = date_object_get_gc; zend_class_implements(date_ce_immutable, 1, date_ce_interface); - INIT_CLASS_ENTRY(ce_timezone, "DateTimeZone", date_funcs_timezone); + INIT_CLASS_ENTRY(ce_timezone, "DateTimeZone", class_DateTimeZone_methods); ce_timezone.create_object = date_object_new_timezone; date_ce_timezone = zend_register_internal_class_ex(&ce_timezone, NULL); memcpy(&date_object_handlers_timezone, &std_object_handlers, sizeof(zend_object_handlers)); @@ -1754,7 +1663,7 @@ static void date_register_classes(void) /* {{{ */ REGISTER_TIMEZONE_CLASS_CONST_STRING("ALL_WITH_BC", PHP_DATE_TIMEZONE_GROUP_ALL_W_BC); REGISTER_TIMEZONE_CLASS_CONST_STRING("PER_COUNTRY", PHP_DATE_TIMEZONE_PER_COUNTRY); - INIT_CLASS_ENTRY(ce_interval, "DateInterval", date_funcs_interval); + INIT_CLASS_ENTRY(ce_interval, "DateInterval", class_DateInterval_methods); ce_interval.create_object = date_object_new_interval; date_ce_interval = zend_register_internal_class_ex(&ce_interval, NULL); memcpy(&date_object_handlers_interval, &std_object_handlers, sizeof(zend_object_handlers)); @@ -1769,7 +1678,7 @@ static void date_register_classes(void) /* {{{ */ date_object_handlers_interval.get_gc = date_object_get_gc_interval; date_object_handlers_interval.compare = date_interval_compare_objects; - INIT_CLASS_ENTRY(ce_period, "DatePeriod", date_funcs_period); + INIT_CLASS_ENTRY(ce_period, "DatePeriod", class_DatePeriod_methods); ce_period.create_object = date_object_new_period; date_ce_period = zend_register_internal_class_ex(&ce_period, NULL); date_ce_period->get_iterator = date_object_period_get_iterator; @@ -2691,6 +2600,26 @@ PHP_METHOD(DateTime, __wakeup) } /* }}} */ +/* {{{ proto DateTimeImmutable::__wakeup() +*/ +PHP_METHOD(DateTimeImmutable, __wakeup) +{ + zval *object = ZEND_THIS; + php_date_obj *dateobj; + HashTable *myht; + + ZEND_PARSE_PARAMETERS_NONE(); + + dateobj = Z_PHPDATE_P(object); + + myht = Z_OBJPROP_P(object); + + if (!php_date_initialize_from_hash(&dateobj, myht)) { + zend_throw_error(NULL, "Invalid serialization data for DateTimeImmutable object"); + } +} +/* }}} */ + /* Helper function used to add an associative array of warnings and errors to a zval */ static void zval_from_error_container(zval *z, timelib_error_container *error) /* {{{ */ { |
