1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | http://www.php.net/license/3_01.txt                                  |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Gustavo Lopes <cataphract@php.net>                          |
14    +----------------------------------------------------------------------+
15 */
16 
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include "../intl_cppshims.h"
23 
24 #include <unicode/timezone.h>
25 #include <unicode/calendar.h>
26 #include "../intl_convertcpp.h"
27 
28 #include "../common/common_date.h"
29 
30 extern "C" {
31 #include "../intl_convert.h"
32 #define USE_TIMEZONE_POINTER 1
33 #include "timezone_class.h"
34 #include "timezone_methods.h"
35 #include <zend_exceptions.h>
36 #include <zend_interfaces.h>
37 #include <ext/date/php_date.h>
38 }
39 
40 /* {{{ Global variables */
41 U_CDECL_BEGIN
42 zend_class_entry *TimeZone_ce_ptr = NULL;
43 zend_object_handlers TimeZone_handlers;
44 U_CDECL_END
45 /* }}} */
46 
47 /* {{{ timezone_object_construct */
timezone_object_construct(const TimeZone * zone,zval * object,int owned TSRMLS_DC)48 U_CFUNC void timezone_object_construct(const TimeZone *zone, zval *object, int owned TSRMLS_DC)
49 {
50 	TimeZone_object	*to;
51 
52 	object_init_ex(object, TimeZone_ce_ptr);
53 	TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; /* fetch zend object from zval "object" into "to" */
54 	to->utimezone = zone;
55 	to->should_delete = owned;
56 }
57 /* }}} */
58 
59 /* {{{ timezone_convert_to_datetimezone
60  *	   Convert from TimeZone to DateTimeZone object */
timezone_convert_to_datetimezone(const TimeZone * timeZone,intl_error * outside_error,const char * func TSRMLS_DC)61 U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
62 											   intl_error *outside_error,
63 											   const char *func TSRMLS_DC)
64 {
65 	zval				*ret = NULL;
66 	UnicodeString		id;
67 	char				*message = NULL;
68 	php_timezone_obj	*tzobj;
69 	zval				arg = zval_used_for_init;
70 
71 	timeZone->getID(id);
72 	if (id.isBogus()) {
73 		spprintf(&message, 0, "%s: could not obtain TimeZone id", func);
74 		intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR,
75 			message, 1 TSRMLS_CC);
76 		goto error;
77 	}
78 
79 	MAKE_STD_ZVAL(ret);
80 	object_init_ex(ret, php_date_get_timezone_ce());
81 	tzobj = (php_timezone_obj *)zend_objects_get_address(ret TSRMLS_CC);
82 
83 	if (id.compare(0, 3, UnicodeString("GMT", sizeof("GMT")-1, US_INV)) == 0) {
84 		/* The DateTimeZone constructor doesn't support offset time zones,
85 		 * so we must mess with DateTimeZone structure ourselves */
86 		tzobj->initialized	  = 1;
87 		tzobj->type			  = TIMELIB_ZONETYPE_OFFSET;
88 		//convert offset from milliseconds to minutes
89 		tzobj->tzi.utc_offset = -1 * timeZone->getRawOffset() / (60 * 1000);
90 	} else {
91 		/* Call the constructor! */
92 		Z_TYPE(arg) = IS_STRING;
93 		if (intl_charFromString(id, &Z_STRVAL(arg), &Z_STRLEN(arg),
94 				&INTL_ERROR_CODE(*outside_error)) == FAILURE) {
95 			spprintf(&message, 0, "%s: could not convert id to UTF-8", func);
96 			intl_errors_set(outside_error, INTL_ERROR_CODE(*outside_error),
97 				message, 1 TSRMLS_CC);
98 			goto error;
99 		}
100 		zend_call_method_with_1_params(&ret, NULL, NULL, "__construct",
101 			NULL, &arg);
102 		if (EG(exception)) {
103 			spprintf(&message, 0,
104 				"%s: DateTimeZone constructor threw exception", func);
105 			intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR,
106 				message, 1 TSRMLS_CC);
107 			zend_object_store_ctor_failed(ret TSRMLS_CC);
108 			goto error;
109 		}
110 	}
111 
112 	if (0) {
113 error:
114 		if (ret) {
115 			zval_ptr_dtor(&ret);
116 		}
117 		ret = NULL;
118 	}
119 
120 	if (message) {
121 		efree(message);
122 	}
123 	if (Z_TYPE(arg) == IS_STRING) {
124 		zval_dtor(&arg);
125 	}
126 	return ret;
127 }
128 /* }}} */
129 
130 /* {{{ timezone_process_timezone_argument
131  * TimeZone argument processor. outside_error may be NULL (for static functions/constructors) */
timezone_process_timezone_argument(zval ** zv_timezone,intl_error * outside_error,const char * func TSRMLS_DC)132 U_CFUNC TimeZone *timezone_process_timezone_argument(zval **zv_timezone,
133 													 intl_error *outside_error,
134 													 const char *func TSRMLS_DC)
135 {
136 	zval		local_zv_tz		= zval_used_for_init,
137 				*local_zv_tz_p	= &local_zv_tz;
138 	char		*message = NULL;
139 	TimeZone	*timeZone;
140 
141 	if (zv_timezone == NULL || Z_TYPE_PP(zv_timezone) == IS_NULL) {
142 		timelib_tzinfo *tzinfo = get_timezone_info(TSRMLS_C);
143 		ZVAL_STRING(&local_zv_tz, tzinfo->name, 0);
144 		zv_timezone = &local_zv_tz_p;
145 	}
146 
147 	if (Z_TYPE_PP(zv_timezone) == IS_OBJECT &&
148 			instanceof_function(Z_OBJCE_PP(zv_timezone), TimeZone_ce_ptr TSRMLS_CC)) {
149 		TimeZone_object *to = (TimeZone_object*)zend_objects_get_address(
150 			*zv_timezone TSRMLS_CC);
151 		if (to->utimezone == NULL) {
152 			spprintf(&message, 0, "%s: passed IntlTimeZone is not "
153 				"properly constructed", func);
154 			if (message) {
155 				intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC);
156 				efree(message);
157 			}
158 			return NULL;
159 		}
160 		timeZone = to->utimezone->clone();
161 		if (timeZone == NULL) {
162 			spprintf(&message, 0, "%s: could not clone TimeZone", func);
163 			if (message) {
164 				intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1 TSRMLS_CC);
165 				efree(message);
166 			}
167 			return NULL;
168 		}
169 	} else if (Z_TYPE_PP(zv_timezone) == IS_OBJECT &&
170 			instanceof_function(Z_OBJCE_PP(zv_timezone), php_date_get_timezone_ce() TSRMLS_CC)) {
171 
172 		php_timezone_obj *tzobj = (php_timezone_obj *)zend_objects_get_address(
173 				*zv_timezone TSRMLS_CC);
174 
175 		return timezone_convert_datetimezone(tzobj->type, tzobj, 0,
176 			outside_error, func TSRMLS_CC);
177 	} else {
178 		UnicodeString	id,
179 						gottenId;
180 		UErrorCode		status = U_ZERO_ERROR; /* outside_error may be NULL */
181 		convert_to_string_ex(zv_timezone);
182 		if (intl_stringFromChar(id, Z_STRVAL_PP(zv_timezone), Z_STRLEN_PP(zv_timezone),
183 				&status) == FAILURE) {
184 			spprintf(&message, 0, "%s: Time zone identifier given is not a "
185 				"valid UTF-8 string", func);
186 			if (message) {
187 				intl_errors_set(outside_error, status, message, 1 TSRMLS_CC);
188 				efree(message);
189 			}
190 			return NULL;
191 		}
192 		timeZone = TimeZone::createTimeZone(id);
193 		if (timeZone == NULL) {
194 			spprintf(&message, 0, "%s: could not create time zone", func);
195 			if (message) {
196 				intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1 TSRMLS_CC);
197 				efree(message);
198 			}
199 			return NULL;
200 		}
201 		if (timeZone->getID(gottenId) != id) {
202 			spprintf(&message, 0, "%s: no such time zone: '%s'",
203 				func, Z_STRVAL_PP(zv_timezone));
204 			if (message) {
205 				intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC);
206 				efree(message);
207 			}
208 			delete timeZone;
209 			return NULL;
210 		}
211 	}
212 
213 	return timeZone;
214 }
215 /* }}} */
216 
217 /* {{{ clone handler for TimeZone */
TimeZone_clone_obj(zval * object TSRMLS_DC)218 static zend_object_value TimeZone_clone_obj(zval *object TSRMLS_DC)
219 {
220 	TimeZone_object		*to_orig,
221 						*to_new;
222 	zend_object_value   ret_val;
223 	intl_error_reset(NULL TSRMLS_CC);
224 
225 	to_orig = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC);
226 	intl_error_reset(TIMEZONE_ERROR_P(to_orig) TSRMLS_CC);
227 
228 	ret_val = TimeZone_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
229 	to_new  = (TimeZone_object*)zend_object_store_get_object_by_handle(
230 		ret_val.handle TSRMLS_CC);
231 
232 	zend_objects_clone_members(&to_new->zo, ret_val,
233 		&to_orig->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC);
234 
235 	if (to_orig->utimezone != NULL) {
236 		TimeZone	*newTimeZone;
237 
238 		newTimeZone = to_orig->utimezone->clone();
239 		to_new->should_delete = 1;
240 		if (!newTimeZone) {
241 			char *err_msg;
242 			intl_errors_set_code(TIMEZONE_ERROR_P(to_orig),
243 				U_MEMORY_ALLOCATION_ERROR TSRMLS_CC);
244 			intl_errors_set_custom_msg(TIMEZONE_ERROR_P(to_orig),
245 				"Could not clone IntlTimeZone", 0 TSRMLS_CC);
246 			err_msg = intl_error_get_message(TIMEZONE_ERROR_P(to_orig) TSRMLS_CC);
247 			zend_throw_exception(NULL, err_msg, 0 TSRMLS_CC);
248 			efree(err_msg);
249 		} else {
250 			to_new->utimezone = newTimeZone;
251 		}
252 	} else {
253 		zend_throw_exception(NULL, "Cannot clone unconstructed IntlTimeZone", 0 TSRMLS_CC);
254 	}
255 
256 	return ret_val;
257 }
258 /* }}} */
259 
260 /* {{{ compare_objects handler for TimeZone
261  *     Can't be used for >, >=, <, <= comparisons */
TimeZone_compare_objects(zval * object1,zval * object2 TSRMLS_DC)262 static int TimeZone_compare_objects(zval *object1, zval *object2 TSRMLS_DC)
263 {
264 	TimeZone_object		*to1,
265 						*to2;
266 	to1 = (TimeZone_object*)zend_object_store_get_object(object1 TSRMLS_CC);
267 	to2 = (TimeZone_object*)zend_object_store_get_object(object2 TSRMLS_CC);
268 
269 	if (to1->utimezone == NULL || to2->utimezone == NULL) {
270 		zend_throw_exception(NULL, "Comparison with at least one unconstructed "
271 				"IntlTimeZone operand", 0 TSRMLS_CC);
272 		/* intentionally not returning */
273 	} else {
274 		if (*to1->utimezone == *to2->utimezone) {
275 			return 0;
276 		}
277 	}
278 
279 	return 1;
280 }
281 /* }}} */
282 
283 /* {{{ get_debug_info handler for TimeZone */
TimeZone_get_debug_info(zval * object,int * is_temp TSRMLS_DC)284 static HashTable *TimeZone_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
285 {
286 	zval			zv = zval_used_for_init;
287 	TimeZone_object	*to;
288 	const TimeZone	*tz;
289 	UnicodeString	ustr;
290 	char			*str;
291 	int				str_len;
292 	UErrorCode		uec = U_ZERO_ERROR;
293 
294 	*is_temp = 1;
295 
296 	array_init_size(&zv, 4);
297 
298 	to = (TimeZone_object*)zend_object_store_get_object(object TSRMLS_CC);
299 	tz = to->utimezone;
300 
301 	if (tz == NULL) {
302 		add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 0);
303 		return Z_ARRVAL(zv);
304 	}
305 
306 	add_assoc_bool_ex(&zv, "valid", sizeof("valid"), 1);
307 
308 	tz->getID(ustr);
309 	intl_convert_utf16_to_utf8(&str, &str_len,
310 		ustr.getBuffer(), ustr.length(), &uec);
311 	if (U_FAILURE(uec)) {
312 		return Z_ARRVAL(zv);
313 	}
314 	add_assoc_stringl_ex(&zv, "id", sizeof("id"), str, str_len, 0);
315 
316 	int32_t rawOffset, dstOffset;
317 	UDate now = Calendar::getNow();
318 	tz->getOffset(now, FALSE, rawOffset, dstOffset, uec);
319 	if (U_FAILURE(uec)) {
320 		return Z_ARRVAL(zv);
321 	}
322 
323 	add_assoc_long_ex(&zv, "rawOffset", sizeof("rawOffset"), (long)rawOffset);
324 	add_assoc_long_ex(&zv, "currentOffset", sizeof("currentOffset"),
325 		(long)(rawOffset + dstOffset));
326 
327 	return Z_ARRVAL(zv);
328 }
329 /* }}} */
330 
331 /* {{{ void TimeZone_object_init(TimeZone_object* to)
332  * Initialize internals of TImeZone_object not specific to zend standard objects.
333  */
TimeZone_object_init(TimeZone_object * to TSRMLS_DC)334 static void TimeZone_object_init(TimeZone_object *to TSRMLS_DC)
335 {
336 	intl_error_init(TIMEZONE_ERROR_P(to) TSRMLS_CC);
337 	to->utimezone = NULL;
338 	to->should_delete = 0;
339 }
340 /* }}} */
341 
342 /* {{{ TimeZone_objects_dtor */
TimeZone_objects_dtor(zend_object * object,zend_object_handle handle TSRMLS_DC)343 static void TimeZone_objects_dtor(zend_object *object,
344 								   zend_object_handle handle TSRMLS_DC)
345 {
346 	zend_objects_destroy_object(object, handle TSRMLS_CC);
347 }
348 /* }}} */
349 
350 /* {{{ TimeZone_objects_free */
TimeZone_objects_free(zend_object * object TSRMLS_DC)351 static void TimeZone_objects_free(zend_object *object TSRMLS_DC)
352 {
353 	TimeZone_object* to = (TimeZone_object*) object;
354 
355 	if (to->utimezone && to->should_delete) {
356 		delete to->utimezone;
357 		to->utimezone = NULL;
358 	}
359 	intl_error_reset(TIMEZONE_ERROR_P(to) TSRMLS_CC);
360 
361 	zend_object_std_dtor(&to->zo TSRMLS_CC);
362 
363 	efree(to);
364 }
365 /* }}} */
366 
367 /* {{{ TimeZone_object_create */
TimeZone_object_create(zend_class_entry * ce TSRMLS_DC)368 static zend_object_value TimeZone_object_create(zend_class_entry *ce TSRMLS_DC)
369 {
370 	zend_object_value   retval;
371 	TimeZone_object*	intern;
372 
373 	intern = (TimeZone_object*)ecalloc(1, sizeof(TimeZone_object));
374 
375 	zend_object_std_init(&intern->zo, ce TSRMLS_CC);
376 #if PHP_VERSION_ID < 50399
377     zend_hash_copy(intern->zo.properties, &(ce->default_properties),
378         (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
379 #else
380     object_properties_init((zend_object*) intern, ce);
381 #endif
382 	TimeZone_object_init(intern TSRMLS_CC);
383 
384 	retval.handle = zend_objects_store_put(
385 		intern,
386 		(zend_objects_store_dtor_t) TimeZone_objects_dtor,
387 		(zend_objects_free_object_storage_t) TimeZone_objects_free,
388 		NULL TSRMLS_CC);
389 
390 	retval.handlers = &TimeZone_handlers;
391 
392 	return retval;
393 }
394 /* }}} */
395 
396 /* {{{ TimeZone methods arguments info */
397 
398 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_idarg, 0, 0, 1)
399 	ZEND_ARG_INFO(0, zoneId)
400 ZEND_END_ARG_INFO()
401 
402 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_fromDateTimeZone, 0, 0, 1)
403 	ZEND_ARG_OBJ_INFO(0, otherTimeZone, IntlTimeZone, 0)
404 ZEND_END_ARG_INFO()
405 
406 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_createEnumeration, 0, 0, 0)
407 	ZEND_ARG_INFO(0, countryOrRawOffset)
408 ZEND_END_ARG_INFO()
409 
410 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_countEquivalentIDs, 0, 0, 1)
411 	ZEND_ARG_INFO(0, zoneId)
412 ZEND_END_ARG_INFO()
413 
414 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_createTimeZoneIDEnumeration, 0, 0, 1)
415 	ZEND_ARG_INFO(0, zoneType)
416 	ZEND_ARG_INFO(0, region)
417 	ZEND_ARG_INFO(0, rawOffset)
418 ZEND_END_ARG_INFO()
419 
420 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getCanonicalID, 0, 0, 1)
421 	ZEND_ARG_INFO(0, zoneId)
422 	ZEND_ARG_INFO(1, isSystemID)
423 ZEND_END_ARG_INFO()
424 
425 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getEquivalentID, 0, 0, 2)
426 	ZEND_ARG_INFO(0, zoneId)
427 	ZEND_ARG_INFO(0, index)
428 ZEND_END_ARG_INFO()
429 
430 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getOffset, 0, 0, 4)
431 	ZEND_ARG_INFO(0, date)
432 	ZEND_ARG_INFO(0, local)
433 	ZEND_ARG_INFO(1, rawOffset)
434 	ZEND_ARG_INFO(1, dstOffset)
435 ZEND_END_ARG_INFO()
436 
437 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_hasSameRules, 0, 0, 1)
438 	ZEND_ARG_OBJ_INFO(0, otherTimeZone, IntlTimeZone, 0)
439 ZEND_END_ARG_INFO()
440 
441 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_getDisplayName, 0, 0, 0)
442 	ZEND_ARG_INFO(0, isDaylight)
443 	ZEND_ARG_INFO(0, style)
444 	ZEND_ARG_INFO(0, locale)
445 ZEND_END_ARG_INFO()
446 
447 ZEND_BEGIN_ARG_INFO_EX(ainfo_tz_void, 0, 0, 0)
448 ZEND_END_ARG_INFO()
449 
450 /* }}} */
451 
452 /* {{{ TimeZone_class_functions
453  * Every 'IntlTimeZone' class method has an entry in this table
454  */
455 static zend_function_entry TimeZone_class_functions[] = {
456 	PHP_ME(IntlTimeZone,				__construct,					ainfo_tz_void,				ZEND_ACC_PRIVATE)
457 	PHP_ME_MAPPING(createTimeZone,		intltz_create_time_zone,		ainfo_tz_idarg,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
458 	PHP_ME_MAPPING(fromDateTimeZone,	intltz_from_date_time_zone,		ainfo_tz_idarg,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
459 	PHP_ME_MAPPING(createDefault,		intltz_create_default,			ainfo_tz_void,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
460 	PHP_ME_MAPPING(getGMT,				intltz_get_gmt,					ainfo_tz_void,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
461 #if U_ICU_VERSION_MAJOR_NUM >= 49
462 	PHP_ME_MAPPING(getUnknown,			intltz_get_unknown,				ainfo_tz_void,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
463 #endif
464 	PHP_ME_MAPPING(createEnumeration,	intltz_create_enumeration,		ainfo_tz_createEnumeration,	ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
465 	PHP_ME_MAPPING(countEquivalentIDs,	intltz_count_equivalent_ids,	ainfo_tz_idarg,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
466 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48
467 	PHP_ME_MAPPING(createTimeZoneIDEnumeration, intltz_create_time_zone_id_enumeration, ainfo_tz_createTimeZoneIDEnumeration, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
468 #endif
469 	PHP_ME_MAPPING(getCanonicalID,		intltz_get_canonical_id,		ainfo_tz_getCanonicalID,	ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
470 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48
471 	PHP_ME_MAPPING(getRegion,			intltz_get_region,				ainfo_tz_idarg,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
472 #endif
473 	PHP_ME_MAPPING(getTZDataVersion,	intltz_get_tz_data_version,		ainfo_tz_void,				ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
474 	PHP_ME_MAPPING(getEquivalentID,		intltz_get_equivalent_id,		ainfo_tz_getEquivalentID,	ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
475 
476 	PHP_ME_MAPPING(getID,				intltz_get_id,					ainfo_tz_void,				ZEND_ACC_PUBLIC)
477 	PHP_ME_MAPPING(useDaylightTime,		intltz_use_daylight_time,		ainfo_tz_void,				ZEND_ACC_PUBLIC)
478 	PHP_ME_MAPPING(getOffset,			intltz_get_offset,				ainfo_tz_getOffset,			ZEND_ACC_PUBLIC)
479 	PHP_ME_MAPPING(getRawOffset,		intltz_get_raw_offset,			ainfo_tz_void,				ZEND_ACC_PUBLIC)
480 	PHP_ME_MAPPING(hasSameRules,		intltz_has_same_rules,			ainfo_tz_hasSameRules,		ZEND_ACC_PUBLIC)
481 	PHP_ME_MAPPING(getDisplayName,		intltz_get_display_name,		ainfo_tz_getDisplayName,	ZEND_ACC_PUBLIC)
482 	PHP_ME_MAPPING(getDSTSavings,		intltz_get_dst_savings,			ainfo_tz_void,				ZEND_ACC_PUBLIC)
483 	PHP_ME_MAPPING(toDateTimeZone,		intltz_to_date_time_zone,		ainfo_tz_void,				ZEND_ACC_PUBLIC)
484 	PHP_ME_MAPPING(getErrorCode,		intltz_get_error_code,			ainfo_tz_void,				ZEND_ACC_PUBLIC)
485 	PHP_ME_MAPPING(getErrorMessage,		intltz_get_error_message,		ainfo_tz_void,				ZEND_ACC_PUBLIC)
486 	PHP_FE_END
487 };
488 /* }}} */
489 
490 /* {{{ timezone_register_IntlTimeZone_class
491  * Initialize 'IntlTimeZone' class
492  */
timezone_register_IntlTimeZone_class(TSRMLS_D)493 U_CFUNC void timezone_register_IntlTimeZone_class(TSRMLS_D)
494 {
495 	zend_class_entry ce;
496 
497 	/* Create and register 'IntlTimeZone' class. */
498 	INIT_CLASS_ENTRY(ce, "IntlTimeZone", TimeZone_class_functions);
499 	ce.create_object = TimeZone_object_create;
500 	TimeZone_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
501 	if (!TimeZone_ce_ptr) {
502 		//can't happen now without bigger problems before
503 		php_error_docref0(NULL TSRMLS_CC, E_ERROR,
504 			"IntlTimeZone: class registration has failed.");
505 		return;
506 	}
507 
508 	memcpy(&TimeZone_handlers, zend_get_std_object_handlers(),
509 		sizeof TimeZone_handlers);
510 	TimeZone_handlers.clone_obj = TimeZone_clone_obj;
511 	TimeZone_handlers.compare_objects = TimeZone_compare_objects;
512 	TimeZone_handlers.get_debug_info = TimeZone_get_debug_info;
513 
514 	/* Declare 'IntlTimeZone' class constants */
515 #define TIMEZONE_DECL_LONG_CONST(name, val) \
516 	zend_declare_class_constant_long(TimeZone_ce_ptr, name, sizeof(name) - 1, \
517 		val TSRMLS_CC)
518 
519 	TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT", TimeZone::SHORT);
520 	TIMEZONE_DECL_LONG_CONST("DISPLAY_LONG", TimeZone::LONG);
521 
522 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
523 	TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT_GENERIC", TimeZone::SHORT_GENERIC);
524 	TIMEZONE_DECL_LONG_CONST("DISPLAY_LONG_GENERIC", TimeZone::LONG_GENERIC);
525 	TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT_GMT", TimeZone::SHORT_GMT);
526 	TIMEZONE_DECL_LONG_CONST("DISPLAY_LONG_GMT", TimeZone::LONG_GMT);
527 	TIMEZONE_DECL_LONG_CONST("DISPLAY_SHORT_COMMONLY_USED", TimeZone::SHORT_COMMONLY_USED);
528 	TIMEZONE_DECL_LONG_CONST("DISPLAY_GENERIC_LOCATION", TimeZone::GENERIC_LOCATION);
529 #endif
530 
531 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 48
532 	TIMEZONE_DECL_LONG_CONST("TYPE_ANY", UCAL_ZONE_TYPE_ANY);
533 	TIMEZONE_DECL_LONG_CONST("TYPE_CANONICAL", UCAL_ZONE_TYPE_CANONICAL);
534 	TIMEZONE_DECL_LONG_CONST("TYPE_CANONICAL_LOCATION", UCAL_ZONE_TYPE_CANONICAL_LOCATION);
535 #endif
536 
537 	/* Declare 'IntlTimeZone' class properties */
538 
539 }
540 /* }}} */
541