timezone_class.cpp 18 KB

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