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_free */
Calendar_objects_free(zend_object * object)235 static void Calendar_objects_free(zend_object *object)
236 {
237 Calendar_object* co = php_intl_calendar_fetch_object(object);
238
239 if (co->ucal) {
240 delete co->ucal;
241 co->ucal = NULL;
242 }
243 intl_error_reset(CALENDAR_ERROR_P(co));
244
245 zend_object_std_dtor(&co->zo);
246 }
247 /* }}} */
248
249 /* {{{ Calendar_object_create */
Calendar_object_create(zend_class_entry * ce)250 static zend_object *Calendar_object_create(zend_class_entry *ce)
251 {
252 Calendar_object* intern;
253
254 intern = (Calendar_object*)ecalloc(1, sizeof(Calendar_object) + sizeof(zval) * (ce->default_properties_count - 1));
255
256 zend_object_std_init(&intern->zo, ce);
257 object_properties_init(&intern->zo, ce);
258 calendar_object_init(intern);
259
260
261 intern->zo.handlers = &Calendar_handlers;
262
263 return &intern->zo;
264 }
265 /* }}} */
266
267 /* {{{ Calendar methods arguments info */
268
269 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_void, 0, 0, 0)
270 ZEND_END_ARG_INFO()
271
272 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field, 0, 0, 1)
273 ZEND_ARG_INFO(0, field)
274 ZEND_END_ARG_INFO()
275
276 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_dow, 0, 0, 1)
277 ZEND_ARG_INFO(0, dayOfWeek)
278 ZEND_END_ARG_INFO()
279
280 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_other_cal, 0, 0, 1)
281 ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0)
282 ZEND_END_ARG_INFO()
283
284 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date, 0, 0, 1)
285 ZEND_ARG_INFO(0, date)
286 ZEND_END_ARG_INFO()
287
288 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date_optional, 0, 0, 0)
289 ZEND_ARG_INFO(0, date)
290 ZEND_END_ARG_INFO()
291
292
293 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_createInstance, 0, 0, 0)
294 ZEND_ARG_INFO(0, timeZone)
295 ZEND_ARG_INFO(0, locale)
296 ZEND_END_ARG_INFO()
297
298 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_keyword_values_for_locale, 0, 0, 3)
299 ZEND_ARG_INFO(0, key)
300 ZEND_ARG_INFO(0, locale)
301 ZEND_ARG_INFO(0, commonlyUsed)
302 ZEND_END_ARG_INFO()
303
304 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_add, 0, 0, 2)
305 ZEND_ARG_INFO(0, field)
306 ZEND_ARG_INFO(0, amount)
307 ZEND_END_ARG_INFO()
308
309 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setTimeZone, 0, 0, 1)
310 ZEND_ARG_INFO(0, timeZone)
311 ZEND_END_ARG_INFO()
312
313 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set, 0, 0, 2)
314 ZEND_ARG_INFO(0, fieldOrYear)
315 ZEND_ARG_INFO(0, valueOrMonth)
316 ZEND_ARG_INFO(0, dayOfMonth)
317 ZEND_ARG_INFO(0, hour)
318 ZEND_ARG_INFO(0, minute)
319 ZEND_ARG_INFO(0, second)
320 ZEND_END_ARG_INFO()
321
322 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_roll, 0, 0, 2)
323 ZEND_ARG_INFO(0, field)
324 ZEND_ARG_INFO(0, amountOrUpOrDown)
325 ZEND_END_ARG_INFO()
326
327 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_clear, 0, 0, 0)
328 ZEND_ARG_INFO(0, field)
329 ZEND_END_ARG_INFO()
330
331 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field_difference, 0, 0, 2)
332 ZEND_ARG_INFO(0, when)
333 ZEND_ARG_INFO(0, field)
334 ZEND_END_ARG_INFO()
335
336 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_locale, 0, 0, 1)
337 ZEND_ARG_INFO(0, localeType)
338 ZEND_END_ARG_INFO()
339
340 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setLenient, 0, 0, 1)
341 ZEND_ARG_INFO(0, isLenient)
342 ZEND_END_ARG_INFO()
343
344 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set_minimal_days_in_first_week, 0, 0, 1)
345 ZEND_ARG_INFO(0, numberOfDays)
346 ZEND_END_ARG_INFO()
347
348 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_from_date_time, 0, 0, 1)
349 ZEND_ARG_INFO(0, dateTime)
350 ZEND_END_ARG_INFO()
351
352 ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_wall_time_option, 0, 0, 1)
353 ZEND_ARG_INFO(0, wallTimeOption)
354 ZEND_END_ARG_INFO()
355
356 /* Gregorian Calendar */
357 ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal___construct, 0, 0, 0)
358 ZEND_ARG_INFO(0, timeZoneOrYear)
359 ZEND_ARG_INFO(0, localeOrMonth)
360 ZEND_ARG_INFO(0, dayOfMonth)
361 ZEND_ARG_INFO(0, hour)
362 ZEND_ARG_INFO(0, minute)
363 ZEND_ARG_INFO(0, second)
364 ZEND_END_ARG_INFO()
365
366 ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal_isLeapYear, 0, 0, 1)
367 ZEND_ARG_INFO(0, year)
368 ZEND_END_ARG_INFO()
369
370 /* }}} */
371
372 /* {{{ Calendar_class_functions
373 * Every 'IntlCalendar' class method has an entry in this table
374 */
375 static const zend_function_entry Calendar_class_functions[] = {
376 PHP_ME(IntlCalendar, __construct, ainfo_cal_void, ZEND_ACC_PRIVATE)
377 PHP_ME_MAPPING(createInstance, intlcal_create_instance, ainfo_cal_createInstance, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
378 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42
379 PHP_ME_MAPPING(getKeywordValuesForLocale, intlcal_get_keyword_values_for_locale, ainfo_cal_get_keyword_values_for_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
380 #endif
381 PHP_ME_MAPPING(getNow, intlcal_get_now, ainfo_cal_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
382 PHP_ME_MAPPING(getAvailableLocales, intlcal_get_available_locales, ainfo_cal_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
383 PHP_ME_MAPPING(get, intlcal_get, ainfo_cal_field, ZEND_ACC_PUBLIC)
384 PHP_ME_MAPPING(getTime, intlcal_get_time, ainfo_cal_void, ZEND_ACC_PUBLIC)
385 PHP_ME_MAPPING(setTime, intlcal_set_time, ainfo_cal_date, ZEND_ACC_PUBLIC)
386 PHP_ME_MAPPING(add, intlcal_add, ainfo_cal_add, ZEND_ACC_PUBLIC)
387 PHP_ME_MAPPING(setTimeZone, intlcal_set_time_zone, ainfo_cal_setTimeZone, ZEND_ACC_PUBLIC)
388 PHP_ME_MAPPING(after, intlcal_after, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
389 PHP_ME_MAPPING(before, intlcal_before, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
390 PHP_ME_MAPPING(set, intlcal_set, ainfo_cal_set, ZEND_ACC_PUBLIC)
391 PHP_ME_MAPPING(roll, intlcal_roll, ainfo_cal_roll, ZEND_ACC_PUBLIC)
392 PHP_ME_MAPPING(clear, intlcal_clear, ainfo_cal_clear, ZEND_ACC_PUBLIC)
393 PHP_ME_MAPPING(fieldDifference, intlcal_field_difference, ainfo_cal_field_difference, ZEND_ACC_PUBLIC)
394 PHP_ME_MAPPING(getActualMaximum, intlcal_get_actual_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC)
395 PHP_ME_MAPPING(getActualMinimum, intlcal_get_actual_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC)
396 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
397 PHP_ME_MAPPING(getDayOfWeekType, intlcal_get_day_of_week_type, ainfo_cal_dow, ZEND_ACC_PUBLIC)
398 #endif
399 PHP_ME_MAPPING(getFirstDayOfWeek, intlcal_get_first_day_of_week, ainfo_cal_void, ZEND_ACC_PUBLIC)
400 PHP_ME_MAPPING(getGreatestMinimum, intlcal_get_greatest_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC)
401 PHP_ME_MAPPING(getLeastMaximum, intlcal_get_least_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC)
402 PHP_ME_MAPPING(getLocale, intlcal_get_locale, ainfo_cal_get_locale, ZEND_ACC_PUBLIC)
403 PHP_ME_MAPPING(getMaximum, intlcal_get_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC)
404 PHP_ME_MAPPING(getMinimalDaysInFirstWeek, intlcal_get_minimal_days_in_first_week, ainfo_cal_void, ZEND_ACC_PUBLIC)
405 PHP_ME_MAPPING(getMinimum, intlcal_get_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC)
406 PHP_ME_MAPPING(getTimeZone, intlcal_get_time_zone, ainfo_cal_void, ZEND_ACC_PUBLIC)
407 PHP_ME_MAPPING(getType, intlcal_get_type, ainfo_cal_void, ZEND_ACC_PUBLIC)
408 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
409 PHP_ME_MAPPING(getWeekendTransition,intlcal_get_weekend_transition, ainfo_cal_dow, ZEND_ACC_PUBLIC)
410 #endif
411 PHP_ME_MAPPING(inDaylightTime, intlcal_in_daylight_time, ainfo_cal_void, ZEND_ACC_PUBLIC)
412 PHP_ME_MAPPING(isEquivalentTo, intlcal_is_equivalent_to, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
413 PHP_ME_MAPPING(isLenient, intlcal_is_lenient, ainfo_cal_void, ZEND_ACC_PUBLIC)
414 PHP_ME_MAPPING(isSet, intlcal_is_set, ainfo_cal_field, ZEND_ACC_PUBLIC)
415 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
416 PHP_ME_MAPPING(isWeekend, intlcal_is_weekend, ainfo_cal_date_optional, ZEND_ACC_PUBLIC)
417 #endif
418 PHP_ME_MAPPING(setFirstDayOfWeek, intlcal_set_first_day_of_week, ainfo_cal_dow, ZEND_ACC_PUBLIC)
419 PHP_ME_MAPPING(setLenient, intlcal_set_lenient, ainfo_cal_setLenient, ZEND_ACC_PUBLIC)
420 PHP_ME_MAPPING(setMinimalDaysInFirstWeek,intlcal_set_minimal_days_in_first_week,ainfo_cal_set_minimal_days_in_first_week,ZEND_ACC_PUBLIC)
421 PHP_ME_MAPPING(equals, intlcal_equals, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
422 #if U_ICU_VERSION_MAJOR_NUM >= 49
423 PHP_ME_MAPPING(getRepeatedWallTimeOption,intlcal_get_repeated_wall_time_option,ainfo_cal_void, ZEND_ACC_PUBLIC)
424 PHP_ME_MAPPING(getSkippedWallTimeOption,intlcal_get_skipped_wall_time_option,ainfo_cal_void, ZEND_ACC_PUBLIC)
425 PHP_ME_MAPPING(setRepeatedWallTimeOption,intlcal_set_repeated_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC)
426 PHP_ME_MAPPING(setSkippedWallTimeOption,intlcal_set_skipped_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC)
427 #endif
428 PHP_ME_MAPPING(fromDateTime, intlcal_from_date_time, ainfo_cal_from_date_time, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
429 PHP_ME_MAPPING(toDateTime, intlcal_to_date_time, ainfo_cal_void, ZEND_ACC_PUBLIC)
430 PHP_ME_MAPPING(getErrorCode, intlcal_get_error_code, ainfo_cal_void, ZEND_ACC_PUBLIC)
431 PHP_ME_MAPPING(getErrorMessage, intlcal_get_error_message, ainfo_cal_void, ZEND_ACC_PUBLIC)
432 PHP_FE_END
433 };
434 /* }}} */
435
436 /* {{{ GregorianCalendar_class_functions
437 */
438 static const zend_function_entry GregorianCalendar_class_functions[] = {
439 PHP_ME(IntlGregorianCalendar, __construct, ainfo_gregcal___construct, ZEND_ACC_PUBLIC)
440 PHP_ME_MAPPING(setGregorianChange, intlgregcal_set_gregorian_change, ainfo_cal_date, ZEND_ACC_PUBLIC)
441 PHP_ME_MAPPING(getGregorianChange, intlgregcal_get_gregorian_change, ainfo_cal_void, ZEND_ACC_PUBLIC)
442 PHP_ME_MAPPING(isLeapYear, intlgregcal_is_leap_year, ainfo_gregcal_isLeapYear, ZEND_ACC_PUBLIC)
443 PHP_FE_END
444 };
445 /* }}} */
446
447
448 /* {{{ calendar_register_IntlCalendar_class
449 * Initialize 'IntlCalendar' class
450 */
calendar_register_IntlCalendar_class(void)451 void calendar_register_IntlCalendar_class(void)
452 {
453 zend_class_entry ce;
454
455 /* Create and register 'IntlCalendar' class. */
456 INIT_CLASS_ENTRY(ce, "IntlCalendar", Calendar_class_functions);
457 ce.create_object = Calendar_object_create;
458 Calendar_ce_ptr = zend_register_internal_class(&ce);
459 if (!Calendar_ce_ptr) {
460 //can't happen now without bigger problems before
461 php_error_docref0(NULL, E_ERROR,
462 "IntlCalendar: class registration has failed.");
463 return;
464 }
465 memcpy( &Calendar_handlers, zend_get_std_object_handlers(),
466 sizeof Calendar_handlers);
467 Calendar_handlers.offset = XtOffsetOf(Calendar_object, zo);
468 Calendar_handlers.clone_obj = Calendar_clone_obj;
469 Calendar_handlers.get_debug_info = Calendar_get_debug_info;
470 Calendar_handlers.free_obj = Calendar_objects_free;
471
472 /* Declare 'IntlCalendar' class constants */
473 #define CALENDAR_DECL_LONG_CONST(name, val) \
474 zend_declare_class_constant_long(Calendar_ce_ptr, name, sizeof(name) - 1, \
475 val)
476
477 CALENDAR_DECL_LONG_CONST("FIELD_ERA", UCAL_ERA);
478 CALENDAR_DECL_LONG_CONST("FIELD_YEAR", UCAL_YEAR);
479 CALENDAR_DECL_LONG_CONST("FIELD_MONTH", UCAL_MONTH);
480 CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_YEAR", UCAL_WEEK_OF_YEAR);
481 CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_MONTH", UCAL_WEEK_OF_MONTH);
482 CALENDAR_DECL_LONG_CONST("FIELD_DATE", UCAL_DATE);
483 CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_YEAR", UCAL_DAY_OF_YEAR);
484 CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK", UCAL_DAY_OF_WEEK);
485 CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK_IN_MONTH", UCAL_DAY_OF_WEEK_IN_MONTH);
486 CALENDAR_DECL_LONG_CONST("FIELD_AM_PM", UCAL_AM_PM);
487 CALENDAR_DECL_LONG_CONST("FIELD_HOUR", UCAL_HOUR);
488 CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY", UCAL_HOUR_OF_DAY);
489 CALENDAR_DECL_LONG_CONST("FIELD_MINUTE", UCAL_MINUTE);
490 CALENDAR_DECL_LONG_CONST("FIELD_SECOND", UCAL_SECOND);
491 CALENDAR_DECL_LONG_CONST("FIELD_MILLISECOND", UCAL_MILLISECOND);
492 CALENDAR_DECL_LONG_CONST("FIELD_ZONE_OFFSET", UCAL_ZONE_OFFSET);
493 CALENDAR_DECL_LONG_CONST("FIELD_DST_OFFSET", UCAL_DST_OFFSET);
494 CALENDAR_DECL_LONG_CONST("FIELD_YEAR_WOY", UCAL_YEAR_WOY);
495 CALENDAR_DECL_LONG_CONST("FIELD_DOW_LOCAL", UCAL_DOW_LOCAL);
496 CALENDAR_DECL_LONG_CONST("FIELD_EXTENDED_YEAR", UCAL_EXTENDED_YEAR);
497 CALENDAR_DECL_LONG_CONST("FIELD_JULIAN_DAY", UCAL_JULIAN_DAY);
498 CALENDAR_DECL_LONG_CONST("FIELD_MILLISECONDS_IN_DAY", UCAL_MILLISECONDS_IN_DAY);
499 CALENDAR_DECL_LONG_CONST("FIELD_IS_LEAP_MONTH", UCAL_IS_LEAP_MONTH);
500 CALENDAR_DECL_LONG_CONST("FIELD_FIELD_COUNT", UCAL_FIELD_COUNT);
501 CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_MONTH", UCAL_DAY_OF_MONTH);
502
503 CALENDAR_DECL_LONG_CONST("DOW_SUNDAY", UCAL_SUNDAY);
504 CALENDAR_DECL_LONG_CONST("DOW_MONDAY", UCAL_MONDAY);
505 CALENDAR_DECL_LONG_CONST("DOW_TUESDAY", UCAL_TUESDAY);
506 CALENDAR_DECL_LONG_CONST("DOW_WEDNESDAY", UCAL_WEDNESDAY);
507 CALENDAR_DECL_LONG_CONST("DOW_THURSDAY", UCAL_THURSDAY);
508 CALENDAR_DECL_LONG_CONST("DOW_FRIDAY", UCAL_FRIDAY);
509 CALENDAR_DECL_LONG_CONST("DOW_SATURDAY", UCAL_SATURDAY);
510
511 #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
512 CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKDAY", UCAL_WEEKDAY);
513 CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND", UCAL_WEEKEND);
514 CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_OFFSET", UCAL_WEEKEND_ONSET);
515 CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_CEASE", UCAL_WEEKEND_CEASE);
516 #endif
517
518 #if U_ICU_VERSION_MAJOR_NUM >= 49
519 CALENDAR_DECL_LONG_CONST("WALLTIME_FIRST", UCAL_WALLTIME_FIRST);
520 CALENDAR_DECL_LONG_CONST("WALLTIME_LAST", UCAL_WALLTIME_LAST);
521 CALENDAR_DECL_LONG_CONST("WALLTIME_NEXT_VALID", UCAL_WALLTIME_NEXT_VALID);
522 #endif
523
524 /* Create and register 'IntlGregorianCalendar' class. */
525 INIT_CLASS_ENTRY(ce, "IntlGregorianCalendar", GregorianCalendar_class_functions);
526 GregorianCalendar_ce_ptr = zend_register_internal_class_ex(&ce,
527 Calendar_ce_ptr);
528 if (!GregorianCalendar_ce_ptr) {
529 //can't happen know without bigger problems before
530 php_error_docref0(NULL, E_ERROR,
531 "IntlGregorianCalendar: class registration has failed.");
532 return;
533 }
534 }
535 /* }}} */
536