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