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