1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include "../intl_cppshims.h"
22 
23 #include <unicode/calendar.h>
24 #include <unicode/gregocal.h>
25 
26 extern "C" {
27 #define USE_TIMEZONE_POINTER 1
28 #include "../timezone/timezone_class.h"
29 #define USE_CALENDAR_POINTER 1
30 #include "calendar_class.h"
31 #include "calendar_methods.h"
32 #include "gregoriancalendar_methods.h"
33 #include <zend_exceptions.h>
34 #include <assert.h>
35 }
36 
37 using icu::GregorianCalendar;
38 using icu::Locale;
39 
40 /* {{{ Global variables */
41 zend_class_entry *Calendar_ce_ptr;
42 zend_class_entry *GregorianCalendar_ce_ptr;
43 zend_object_handlers Calendar_handlers;
44 /* }}} */
45 
calendar_object_create(zval * object,Calendar * calendar)46 U_CFUNC	void calendar_object_create(zval *object,
47 									Calendar *calendar)
48 {
49 	UClassID classId = calendar->getDynamicClassID();
50 	zend_class_entry *ce;
51 
52 	//if (dynamic_cast<GregorianCalendar*>(calendar) != NULL) {
53 	if (classId == GregorianCalendar::getStaticClassID()) {
54 		ce = GregorianCalendar_ce_ptr;
55 	} else {
56 		ce = Calendar_ce_ptr;
57 	}
58 
59 	object_init_ex(object, ce);
60 	calendar_object_construct(object, calendar);
61 }
62 
calendar_fetch_native_calendar(zval * object)63 U_CFUNC Calendar *calendar_fetch_native_calendar(zval *object)
64 {
65 	Calendar_object *co = Z_INTL_CALENDAR_P(object);
66 
67 	return co->ucal;
68 }
69 
calendar_object_construct(zval * object,Calendar * calendar)70 U_CFUNC void calendar_object_construct(zval *object,
71 									   Calendar *calendar)
72 {
73 	Calendar_object *co;
74 
75 	CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; //populate to from object
76 	assert(co->ucal == NULL);
77 	co->ucal = (Calendar*)calendar;
78 }
79 
80 /* {{{ clone handler for Calendar */
Calendar_clone_obj(zval * object)81 static zend_object *Calendar_clone_obj(zval *object)
82 {
83 	Calendar_object		*co_orig,
84 						*co_new;
85 	zend_object 	    *ret_val;
86 	intl_error_reset(NULL);
87 
88 	co_orig = Z_INTL_CALENDAR_P(object);
89 	intl_error_reset(INTL_DATA_ERROR_P(co_orig));
90 
91 	ret_val = Calendar_ce_ptr->create_object(Z_OBJCE_P(object));
92 	co_new  = php_intl_calendar_fetch_object(ret_val);
93 
94 	zend_objects_clone_members(&co_new->zo, &co_orig->zo);
95 
96 	if (co_orig->ucal != NULL) {
97 		Calendar	*newCalendar;
98 
99 		newCalendar = co_orig->ucal->clone();
100 		if (!newCalendar) {
101 			zend_string *err_msg;
102 			intl_errors_set_code(CALENDAR_ERROR_P(co_orig),
103 				U_MEMORY_ALLOCATION_ERROR);
104 			intl_errors_set_custom_msg(CALENDAR_ERROR_P(co_orig),
105 				"Could not clone IntlCalendar", 0);
106 			err_msg = intl_error_get_message(CALENDAR_ERROR_P(co_orig));
107 			zend_throw_exception(NULL, ZSTR_VAL(err_msg), 0);
108 			zend_string_free(err_msg);
109 		} else {
110 			co_new->ucal = newCalendar;
111 		}
112 	} else {
113 		zend_throw_exception(NULL, "Cannot clone unconstructed IntlCalendar", 0);
114 	}
115 
116 	return ret_val;
117 }
118 /* }}} */
119 
120 static const struct {
121 	UCalendarDateFields field;
122 	const char			*name;
123 } debug_info_fields[] = {
124 	{UCAL_ERA,					"era"},
125 	{UCAL_YEAR,					"year"},
126 	{UCAL_MONTH,				"month"},
127 	{UCAL_WEEK_OF_YEAR,			"week of year"},
128 	{UCAL_WEEK_OF_MONTH,		"week of month"},
129 	{UCAL_DAY_OF_YEAR,			"day of year"},
130 	{UCAL_DAY_OF_MONTH,			"day of month"},
131 	{UCAL_DAY_OF_WEEK,			"day of week"},
132 	{UCAL_DAY_OF_WEEK_IN_MONTH,	"day of week in month"},
133 	{UCAL_AM_PM,				"AM/PM"},
134 	{UCAL_HOUR,					"hour"},
135 	{UCAL_HOUR_OF_DAY,			"hour of day"},
136 	{UCAL_MINUTE,				"minute"},
137 	{UCAL_SECOND,				"second"},
138 	{UCAL_MILLISECOND,			"millisecond"},
139 	{UCAL_ZONE_OFFSET,			"zone offset"},
140 	{UCAL_DST_OFFSET,			"DST offset"},
141 	{UCAL_YEAR_WOY,				"year for week of year"},
142 	{UCAL_DOW_LOCAL,			"localized day of week"},
143 	{UCAL_EXTENDED_YEAR,		"extended year"},
144 	{UCAL_JULIAN_DAY,			"julian day"},
145 	{UCAL_MILLISECONDS_IN_DAY,	"milliseconds in day"},
146 	{UCAL_IS_LEAP_MONTH,		"is leap month"},
147 };
148 
149 /* {{{ get_debug_info handler for Calendar */
Calendar_get_debug_info(zval * object,int * is_temp)150 static HashTable *Calendar_get_debug_info(zval *object, int *is_temp)
151 {
152 	zval			zv,
153 					zfields;
154 	Calendar_object	*co;
155 	const Calendar	*cal;
156 	HashTable		*debug_info;
157 
158 	*is_temp = 1;
159 
160 	debug_info = zend_new_array(8);
161 
162 	co  = Z_INTL_CALENDAR_P(object);
163 	cal = co->ucal;
164 
165 	if (cal == NULL) {
166 		ZVAL_FALSE(&zv);
167 		zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &zv);
168 		return debug_info;
169 	}
170 	ZVAL_TRUE(&zv);
171 	zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &zv);
172 
173 	ZVAL_STRING(&zv, const_cast<char*>(cal->getType()));
174 	zend_hash_str_update(debug_info, "type", sizeof("type") - 1, &zv);
175 	{
176 		zval		   ztz,
177 					   ztz_debug;
178 		int			   is_tmp;
179 		HashTable	   *debug_info_tz;
180 
181 		timezone_object_construct(&cal->getTimeZone(), &ztz , 0);
182 		debug_info_tz = Z_OBJ_HANDLER(ztz, get_debug_info)(&ztz, &is_tmp);
183 		assert(is_tmp == 1);
184 
185 		array_init(&ztz_debug);
186 		zend_hash_copy(Z_ARRVAL(ztz_debug), debug_info_tz, zval_add_ref);
187 		zend_hash_destroy(debug_info_tz);
188 		FREE_HASHTABLE(debug_info_tz);
189 
190 		zend_hash_str_update(debug_info, "timeZone", sizeof("timeZone") - 1, &ztz_debug);
191 	}
192 
193 	{
194 		UErrorCode	uec		= U_ZERO_ERROR;
195 		Locale		locale	= cal->getLocale(ULOC_VALID_LOCALE, uec);
196 		if (U_SUCCESS(uec)) {
197 			ZVAL_STRING(&zv, const_cast<char*>(locale.getName()));
198 			zend_hash_str_update(debug_info, "locale", sizeof("locale") - 1, &zv);
199 		} else {
200 			ZVAL_STRING(&zv, const_cast<char*>(u_errorName(uec)));
201 			zend_hash_str_update(debug_info, "locale", sizeof("locale") - 1, &zv);
202 		}
203 	}
204 
205 	array_init_size(&zfields, UCAL_FIELD_COUNT);
206 
207 	for (int i = 0;
208 			 i < sizeof(debug_info_fields) / sizeof(*debug_info_fields);
209 			 i++) {
210 		UErrorCode	uec		= U_ZERO_ERROR;
211 		const char	*name	= debug_info_fields[i].name;
212 		int32_t		res		= cal->get(debug_info_fields[i].field, uec);
213 		if (U_SUCCESS(uec)) {
214 			add_assoc_long(&zfields, name, (zend_long)res);
215 		} else {
216 			add_assoc_string(&zfields, name, const_cast<char*>(u_errorName(uec)));
217 		}
218 	}
219 
220 	zend_hash_str_update(debug_info, "fields", sizeof("fields") - 1, &zfields);
221 
222 	return debug_info;
223 }
224 /* }}} */
225 
226 /* {{{ void calendar_object_init(Calendar_object* to)
227  * Initialize internals of Calendar_object not specific to zend standard objects.
228  */
calendar_object_init(Calendar_object * co)229 static void calendar_object_init(Calendar_object *co)
230 {
231 	intl_error_init(CALENDAR_ERROR_P(co));
232 	co->ucal = NULL;
233 }
234 /* }}} */
235 
236 /* {{{ Calendar_objects_free */
Calendar_objects_free(zend_object * object)237 static void Calendar_objects_free(zend_object *object)
238 {
239 	Calendar_object* co = php_intl_calendar_fetch_object(object);
240 
241 	if (co->ucal) {
242 		delete co->ucal;
243 		co->ucal = NULL;
244 	}
245 	intl_error_reset(CALENDAR_ERROR_P(co));
246 
247 	zend_object_std_dtor(&co->zo);
248 }
249 /* }}} */
250 
251 /* {{{ Calendar_object_create */
Calendar_object_create(zend_class_entry * ce)252 static zend_object *Calendar_object_create(zend_class_entry *ce)
253 {
254 	Calendar_object*	intern;
255 
256 	intern = (Calendar_object*)ecalloc(1, sizeof(Calendar_object) + sizeof(zval) * (ce->default_properties_count - 1));
257 
258 	zend_object_std_init(&intern->zo, ce);
259     object_properties_init(&intern->zo, ce);
260 	calendar_object_init(intern);
261 
262 
263 	intern->zo.handlers = &Calendar_handlers;
264 
265 	return &intern->zo;
266 }
267 /* }}} */
268 
269 /* {{{ Calendar methods arguments info */
270 
271 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_void, 0, 0, 0)
272 ZEND_END_ARG_INFO()
273 
274 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field, 0, 0, 1)
275 	ZEND_ARG_INFO(0, field)
276 ZEND_END_ARG_INFO()
277 
278 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_dow, 0, 0, 1)
279 	ZEND_ARG_INFO(0, dayOfWeek)
280 ZEND_END_ARG_INFO()
281 
282 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_other_cal, 0, 0, 1)
283 	ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0)
284 ZEND_END_ARG_INFO()
285 
286 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date, 0, 0, 1)
287 	ZEND_ARG_INFO(0, date)
288 ZEND_END_ARG_INFO()
289 
290 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date_optional, 0, 0, 0)
291 	ZEND_ARG_INFO(0, date)
292 ZEND_END_ARG_INFO()
293 
294 
295 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_createInstance, 0, 0, 0)
296 	ZEND_ARG_INFO(0, timeZone)
297 	ZEND_ARG_INFO(0, locale)
298 ZEND_END_ARG_INFO()
299 
300 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_keyword_values_for_locale, 0, 0, 3)
301 	ZEND_ARG_INFO(0, key)
302 	ZEND_ARG_INFO(0, locale)
303 	ZEND_ARG_INFO(0, commonlyUsed)
304 ZEND_END_ARG_INFO()
305 
306 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_add, 0, 0, 2)
307 	ZEND_ARG_INFO(0, field)
308 	ZEND_ARG_INFO(0, amount)
309 ZEND_END_ARG_INFO()
310 
311 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setTimeZone, 0, 0, 1)
312 	ZEND_ARG_INFO(0, timeZone)
313 ZEND_END_ARG_INFO()
314 
315 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set, 0, 0, 2)
316 	ZEND_ARG_INFO(0, fieldOrYear)
317 	ZEND_ARG_INFO(0, valueOrMonth)
318 	ZEND_ARG_INFO(0, dayOfMonth)
319 	ZEND_ARG_INFO(0, hour)
320 	ZEND_ARG_INFO(0, minute)
321 	ZEND_ARG_INFO(0, second)
322 ZEND_END_ARG_INFO()
323 
324 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_roll, 0, 0, 2)
325 	ZEND_ARG_INFO(0, field)
326 	ZEND_ARG_INFO(0, amountOrUpOrDown)
327 ZEND_END_ARG_INFO()
328 
329 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_clear, 0, 0, 0)
330 	ZEND_ARG_INFO(0, field)
331 ZEND_END_ARG_INFO()
332 
333 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field_difference, 0, 0, 2)
334 	ZEND_ARG_INFO(0, when)
335 	ZEND_ARG_INFO(0, field)
336 ZEND_END_ARG_INFO()
337 
338 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_locale, 0, 0, 1)
339 	ZEND_ARG_INFO(0, localeType)
340 ZEND_END_ARG_INFO()
341 
342 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setLenient, 0, 0, 1)
343 	ZEND_ARG_INFO(0, isLenient)
344 ZEND_END_ARG_INFO()
345 
346 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set_minimal_days_in_first_week, 0, 0, 1)
347 	ZEND_ARG_INFO(0, numberOfDays)
348 ZEND_END_ARG_INFO()
349 
350 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_from_date_time, 0, 0, 1)
351 	ZEND_ARG_INFO(0, dateTime)
352 ZEND_END_ARG_INFO()
353 
354 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_wall_time_option, 0, 0, 1)
355 	ZEND_ARG_INFO(0, wallTimeOption)
356 ZEND_END_ARG_INFO()
357 
358 /* Gregorian Calendar */
359 ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal___construct, 0, 0, 0)
360 	ZEND_ARG_INFO(0, timeZoneOrYear)
361 	ZEND_ARG_INFO(0, localeOrMonth)
362 	ZEND_ARG_INFO(0, dayOfMonth)
363 	ZEND_ARG_INFO(0, hour)
364 	ZEND_ARG_INFO(0, minute)
365 	ZEND_ARG_INFO(0, second)
366 ZEND_END_ARG_INFO()
367 
368 ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal_isLeapYear, 0, 0, 1)
369 	ZEND_ARG_INFO(0, year)
370 ZEND_END_ARG_INFO()
371 
372 /* }}} */
373 
374 /* {{{ Calendar_class_functions
375  * Every 'IntlCalendar' class method has an entry in this table
376  */
377 static const zend_function_entry Calendar_class_functions[] = {
378 	PHP_ME(IntlCalendar,				__construct,				ainfo_cal_void,						ZEND_ACC_PRIVATE)
379 	PHP_ME_MAPPING(createInstance,		intlcal_create_instance,	ainfo_cal_createInstance,			ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
380 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42
381 	PHP_ME_MAPPING(getKeywordValuesForLocale, intlcal_get_keyword_values_for_locale, ainfo_cal_get_keyword_values_for_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
382 #endif
383 	PHP_ME_MAPPING(getNow,				intlcal_get_now,			ainfo_cal_void,						ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
384 	PHP_ME_MAPPING(getAvailableLocales,	intlcal_get_available_locales, ainfo_cal_void,					ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
385 	PHP_ME_MAPPING(get,					intlcal_get,				ainfo_cal_field,					ZEND_ACC_PUBLIC)
386 	PHP_ME_MAPPING(getTime,				intlcal_get_time,			ainfo_cal_void,						ZEND_ACC_PUBLIC)
387 	PHP_ME_MAPPING(setTime,				intlcal_set_time,			ainfo_cal_date,						ZEND_ACC_PUBLIC)
388 	PHP_ME_MAPPING(add,					intlcal_add,				ainfo_cal_add,						ZEND_ACC_PUBLIC)
389 	PHP_ME_MAPPING(setTimeZone,			intlcal_set_time_zone,		ainfo_cal_setTimeZone,				ZEND_ACC_PUBLIC)
390 	PHP_ME_MAPPING(after,				intlcal_after,				ainfo_cal_other_cal,				ZEND_ACC_PUBLIC)
391 	PHP_ME_MAPPING(before,				intlcal_before,				ainfo_cal_other_cal,				ZEND_ACC_PUBLIC)
392 	PHP_ME_MAPPING(set,					intlcal_set,				ainfo_cal_set,						ZEND_ACC_PUBLIC)
393 	PHP_ME_MAPPING(roll,				intlcal_roll,				ainfo_cal_roll,						ZEND_ACC_PUBLIC)
394 	PHP_ME_MAPPING(clear,				intlcal_clear,				ainfo_cal_clear,					ZEND_ACC_PUBLIC)
395 	PHP_ME_MAPPING(fieldDifference,		intlcal_field_difference,	ainfo_cal_field_difference,			ZEND_ACC_PUBLIC)
396 	PHP_ME_MAPPING(getActualMaximum,	intlcal_get_actual_maximum,	ainfo_cal_field,					ZEND_ACC_PUBLIC)
397 	PHP_ME_MAPPING(getActualMinimum,	intlcal_get_actual_minimum,	ainfo_cal_field,					ZEND_ACC_PUBLIC)
398 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
399 	PHP_ME_MAPPING(getDayOfWeekType,	intlcal_get_day_of_week_type, ainfo_cal_dow,					ZEND_ACC_PUBLIC)
400 #endif
401 	PHP_ME_MAPPING(getFirstDayOfWeek,	intlcal_get_first_day_of_week, ainfo_cal_void,					ZEND_ACC_PUBLIC)
402 	PHP_ME_MAPPING(getGreatestMinimum,	intlcal_get_greatest_minimum, ainfo_cal_field,					ZEND_ACC_PUBLIC)
403 	PHP_ME_MAPPING(getLeastMaximum,		intlcal_get_least_maximum,	ainfo_cal_field,					ZEND_ACC_PUBLIC)
404 	PHP_ME_MAPPING(getLocale,			intlcal_get_locale,			ainfo_cal_get_locale,				ZEND_ACC_PUBLIC)
405 	PHP_ME_MAPPING(getMaximum,			intlcal_get_maximum,		ainfo_cal_field,					ZEND_ACC_PUBLIC)
406 	PHP_ME_MAPPING(getMinimalDaysInFirstWeek, intlcal_get_minimal_days_in_first_week, ainfo_cal_void,	ZEND_ACC_PUBLIC)
407 	PHP_ME_MAPPING(getMinimum,			intlcal_get_minimum,		ainfo_cal_field,					ZEND_ACC_PUBLIC)
408 	PHP_ME_MAPPING(getTimeZone,			intlcal_get_time_zone,		ainfo_cal_void,						ZEND_ACC_PUBLIC)
409 	PHP_ME_MAPPING(getType,				intlcal_get_type,			ainfo_cal_void,						ZEND_ACC_PUBLIC)
410 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
411 	PHP_ME_MAPPING(getWeekendTransition,intlcal_get_weekend_transition, ainfo_cal_dow,					ZEND_ACC_PUBLIC)
412 #endif
413 	PHP_ME_MAPPING(inDaylightTime,		intlcal_in_daylight_time,	ainfo_cal_void,						ZEND_ACC_PUBLIC)
414 	PHP_ME_MAPPING(isEquivalentTo,		intlcal_is_equivalent_to,	ainfo_cal_other_cal,				ZEND_ACC_PUBLIC)
415 	PHP_ME_MAPPING(isLenient,			intlcal_is_lenient,			ainfo_cal_void,						ZEND_ACC_PUBLIC)
416 	PHP_ME_MAPPING(isSet,				intlcal_is_set,				ainfo_cal_field,					ZEND_ACC_PUBLIC)
417 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
418 	PHP_ME_MAPPING(isWeekend,			intlcal_is_weekend,			ainfo_cal_date_optional,			ZEND_ACC_PUBLIC)
419 #endif
420 	PHP_ME_MAPPING(setFirstDayOfWeek,	intlcal_set_first_day_of_week, ainfo_cal_dow,					ZEND_ACC_PUBLIC)
421 	PHP_ME_MAPPING(setLenient,			intlcal_set_lenient,		ainfo_cal_setLenient,				ZEND_ACC_PUBLIC)
422 	PHP_ME_MAPPING(setMinimalDaysInFirstWeek,intlcal_set_minimal_days_in_first_week,ainfo_cal_set_minimal_days_in_first_week,ZEND_ACC_PUBLIC)
423 	PHP_ME_MAPPING(equals,				intlcal_equals,				ainfo_cal_other_cal,				ZEND_ACC_PUBLIC)
424 #if U_ICU_VERSION_MAJOR_NUM >= 49
425 	PHP_ME_MAPPING(getRepeatedWallTimeOption,intlcal_get_repeated_wall_time_option,ainfo_cal_void,		ZEND_ACC_PUBLIC)
426 	PHP_ME_MAPPING(getSkippedWallTimeOption,intlcal_get_skipped_wall_time_option,ainfo_cal_void,		ZEND_ACC_PUBLIC)
427 	PHP_ME_MAPPING(setRepeatedWallTimeOption,intlcal_set_repeated_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC)
428 	PHP_ME_MAPPING(setSkippedWallTimeOption,intlcal_set_skipped_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC)
429 #endif
430 	PHP_ME_MAPPING(fromDateTime,		intlcal_from_date_time,		ainfo_cal_from_date_time,			ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
431 	PHP_ME_MAPPING(toDateTime,			intlcal_to_date_time,		ainfo_cal_void,						ZEND_ACC_PUBLIC)
432 	PHP_ME_MAPPING(getErrorCode,		intlcal_get_error_code,		ainfo_cal_void,						ZEND_ACC_PUBLIC)
433 	PHP_ME_MAPPING(getErrorMessage,		intlcal_get_error_message,	ainfo_cal_void,						ZEND_ACC_PUBLIC)
434 	PHP_FE_END
435 };
436 /* }}} */
437 
438 /* {{{ GregorianCalendar_class_functions
439  */
440 static const zend_function_entry GregorianCalendar_class_functions[] = {
441 	PHP_ME(IntlGregorianCalendar,		__construct,				ainfo_gregcal___construct,			ZEND_ACC_PUBLIC)
442 	PHP_ME_MAPPING(setGregorianChange,	intlgregcal_set_gregorian_change, ainfo_cal_date,				ZEND_ACC_PUBLIC)
443 	PHP_ME_MAPPING(getGregorianChange,	intlgregcal_get_gregorian_change, ainfo_cal_void,				ZEND_ACC_PUBLIC)
444 	PHP_ME_MAPPING(isLeapYear,			intlgregcal_is_leap_year,	ainfo_gregcal_isLeapYear,			ZEND_ACC_PUBLIC)
445 	PHP_FE_END
446 };
447 /* }}} */
448 
449 
450 /* {{{ calendar_register_IntlCalendar_class
451  * Initialize 'IntlCalendar' class
452  */
calendar_register_IntlCalendar_class(void)453 void calendar_register_IntlCalendar_class(void)
454 {
455 	zend_class_entry ce;
456 
457 	/* Create and register 'IntlCalendar' class. */
458 	INIT_CLASS_ENTRY(ce, "IntlCalendar", Calendar_class_functions);
459 	ce.create_object = Calendar_object_create;
460 	Calendar_ce_ptr = zend_register_internal_class(&ce);
461 
462 	memcpy( &Calendar_handlers, &std_object_handlers,
463 		sizeof Calendar_handlers);
464 	Calendar_handlers.offset = XtOffsetOf(Calendar_object, zo);
465 	Calendar_handlers.clone_obj = Calendar_clone_obj;
466 	Calendar_handlers.get_debug_info = Calendar_get_debug_info;
467 	Calendar_handlers.free_obj = Calendar_objects_free;
468 
469 	/* Declare 'IntlCalendar' class constants */
470 #define CALENDAR_DECL_LONG_CONST(name, val) \
471 	zend_declare_class_constant_long(Calendar_ce_ptr, name, sizeof(name) - 1, \
472 		val)
473 
474 	CALENDAR_DECL_LONG_CONST("FIELD_ERA",					UCAL_ERA);
475 	CALENDAR_DECL_LONG_CONST("FIELD_YEAR",					UCAL_YEAR);
476 	CALENDAR_DECL_LONG_CONST("FIELD_MONTH",					UCAL_MONTH);
477 	CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_YEAR",			UCAL_WEEK_OF_YEAR);
478 	CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_MONTH",			UCAL_WEEK_OF_MONTH);
479 	CALENDAR_DECL_LONG_CONST("FIELD_DATE",					UCAL_DATE);
480 	CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_YEAR",			UCAL_DAY_OF_YEAR);
481 	CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK",			UCAL_DAY_OF_WEEK);
482 	CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK_IN_MONTH",	UCAL_DAY_OF_WEEK_IN_MONTH);
483 	CALENDAR_DECL_LONG_CONST("FIELD_AM_PM",					UCAL_AM_PM);
484 	CALENDAR_DECL_LONG_CONST("FIELD_HOUR",					UCAL_HOUR);
485 	CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY",			UCAL_HOUR_OF_DAY);
486 	CALENDAR_DECL_LONG_CONST("FIELD_MINUTE",				UCAL_MINUTE);
487 	CALENDAR_DECL_LONG_CONST("FIELD_SECOND",				UCAL_SECOND);
488 	CALENDAR_DECL_LONG_CONST("FIELD_MILLISECOND",			UCAL_MILLISECOND);
489 	CALENDAR_DECL_LONG_CONST("FIELD_ZONE_OFFSET",			UCAL_ZONE_OFFSET);
490 	CALENDAR_DECL_LONG_CONST("FIELD_DST_OFFSET",			UCAL_DST_OFFSET);
491 	CALENDAR_DECL_LONG_CONST("FIELD_YEAR_WOY",				UCAL_YEAR_WOY);
492 	CALENDAR_DECL_LONG_CONST("FIELD_DOW_LOCAL",				UCAL_DOW_LOCAL);
493 	CALENDAR_DECL_LONG_CONST("FIELD_EXTENDED_YEAR",			UCAL_EXTENDED_YEAR);
494 	CALENDAR_DECL_LONG_CONST("FIELD_JULIAN_DAY",			UCAL_JULIAN_DAY);
495 	CALENDAR_DECL_LONG_CONST("FIELD_MILLISECONDS_IN_DAY",	UCAL_MILLISECONDS_IN_DAY);
496 	CALENDAR_DECL_LONG_CONST("FIELD_IS_LEAP_MONTH",			UCAL_IS_LEAP_MONTH);
497 	CALENDAR_DECL_LONG_CONST("FIELD_FIELD_COUNT",			UCAL_FIELD_COUNT);
498 	CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_MONTH",			UCAL_DAY_OF_MONTH);
499 
500 	CALENDAR_DECL_LONG_CONST("DOW_SUNDAY",					UCAL_SUNDAY);
501 	CALENDAR_DECL_LONG_CONST("DOW_MONDAY",					UCAL_MONDAY);
502 	CALENDAR_DECL_LONG_CONST("DOW_TUESDAY",					UCAL_TUESDAY);
503 	CALENDAR_DECL_LONG_CONST("DOW_WEDNESDAY",				UCAL_WEDNESDAY);
504 	CALENDAR_DECL_LONG_CONST("DOW_THURSDAY",				UCAL_THURSDAY);
505 	CALENDAR_DECL_LONG_CONST("DOW_FRIDAY",					UCAL_FRIDAY);
506 	CALENDAR_DECL_LONG_CONST("DOW_SATURDAY",				UCAL_SATURDAY);
507 
508 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
509 	CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKDAY",			UCAL_WEEKDAY);
510 	CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND",			UCAL_WEEKEND);
511 	CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_OFFSET",		UCAL_WEEKEND_ONSET);
512 	CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_CEASE",		UCAL_WEEKEND_CEASE);
513 #endif
514 
515 #if U_ICU_VERSION_MAJOR_NUM >= 49
516 	CALENDAR_DECL_LONG_CONST("WALLTIME_FIRST",				UCAL_WALLTIME_FIRST);
517 	CALENDAR_DECL_LONG_CONST("WALLTIME_LAST",				UCAL_WALLTIME_LAST);
518 	CALENDAR_DECL_LONG_CONST("WALLTIME_NEXT_VALID",			UCAL_WALLTIME_NEXT_VALID);
519 #endif
520 
521 	/* Create and register 'IntlGregorianCalendar' class. */
522 	INIT_CLASS_ENTRY(ce, "IntlGregorianCalendar", GregorianCalendar_class_functions);
523 	GregorianCalendar_ce_ptr = zend_register_internal_class_ex(&ce,
524 		Calendar_ce_ptr);
525 }
526 /* }}} */
527