1 /*
2 +----------------------------------------------------------------------+
3 | This source file is subject to version 3.01 of the PHP license, |
4 | that is bundled with this package in the file LICENSE, and is |
5 | available through the world-wide-web at the following url: |
6 | https://www.php.net/license/3_01.txt |
7 | If you did not receive a copy of the PHP license and are unable to |
8 | obtain it through the world-wide-web, please send a note to |
9 | license@php.net so we can mail you a copy immediately. |
10 +----------------------------------------------------------------------+
11 | Authors: Kirti Velankar <kirtig@yahoo-inc.com> |
12 +----------------------------------------------------------------------+
13 */
14 #include <unicode/unum.h>
15
16 #include "dateformat_class.h"
17 #include "php_intl.h"
18 #include "dateformat_data.h"
19 #include "dateformat.h"
20 #include "dateformat_arginfo.h"
21
22 #include <zend_exceptions.h>
23
24 zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
25 static zend_object_handlers IntlDateFormatter_handlers;
26
27 /*
28 * Auxiliary functions needed by objects of 'IntlDateFormatter' class
29 */
30
31 /* {{{ IntlDateFormatter_objects_free */
IntlDateFormatter_object_free(zend_object * object)32 void IntlDateFormatter_object_free( zend_object *object )
33 {
34 IntlDateFormatter_object* dfo = php_intl_dateformatter_fetch_object(object);
35
36 zend_object_std_dtor( &dfo->zo );
37
38 if (dfo->requested_locale) {
39 efree( dfo->requested_locale );
40 }
41
42 dateformat_data_free( &dfo->datef_data );
43 }
44 /* }}} */
45
46 /* {{{ IntlDateFormatter_object_create */
IntlDateFormatter_object_create(zend_class_entry * ce)47 zend_object *IntlDateFormatter_object_create(zend_class_entry *ce)
48 {
49 IntlDateFormatter_object* intern;
50
51 intern = zend_object_alloc(sizeof(IntlDateFormatter_object), ce);
52 dateformat_data_init( &intern->datef_data );
53 zend_object_std_init( &intern->zo, ce );
54 object_properties_init(&intern->zo, ce);
55 intern->date_type = 0;
56 intern->time_type = 0;
57 intern->calendar = -1;
58 intern->requested_locale = NULL;
59
60 intern->zo.handlers = &IntlDateFormatter_handlers;
61
62 return &intern->zo;
63 }
64 /* }}} */
65
66 /* {{{ IntlDateFormatter_object_clone */
IntlDateFormatter_object_clone(zend_object * object)67 zend_object *IntlDateFormatter_object_clone(zend_object *object)
68 {
69 IntlDateFormatter_object *dfo, *new_dfo;
70 zend_object *new_obj;
71
72 dfo = php_intl_dateformatter_fetch_object(object);
73 intl_error_reset(INTL_DATA_ERROR_P(dfo));
74
75 new_obj = IntlDateFormatter_ce_ptr->create_object(object->ce);
76 new_dfo = php_intl_dateformatter_fetch_object(new_obj);
77 /* clone standard parts */
78 zend_objects_clone_members(&new_dfo->zo, &dfo->zo);
79 /* clone formatter object */
80 if (dfo->datef_data.udatf != NULL) {
81 DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &INTL_DATA_ERROR_CODE(dfo));
82 if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
83 /* set up error in case error handler is interested */
84 intl_errors_set(INTL_DATA_ERROR_P(dfo), INTL_DATA_ERROR_CODE(dfo),
85 "Failed to clone IntlDateFormatter object", 0 );
86 zend_throw_exception(NULL, "Failed to clone IntlDateFormatter object", 0);
87 }
88 } else {
89 zend_throw_exception(NULL, "Cannot clone unconstructed IntlDateFormatter", 0);
90 }
91 return new_obj;
92 }
93 /* }}} */
94
95 /*
96 * 'IntlDateFormatter' class registration structures & functions
97 */
98
99 /* {{{ dateformat_register_class
100 * Initialize 'IntlDateFormatter' class
101 */
dateformat_register_IntlDateFormatter_class(void)102 void dateformat_register_IntlDateFormatter_class( void )
103 {
104 /* Create and register 'IntlDateFormatter' class. */
105 IntlDateFormatter_ce_ptr = register_class_IntlDateFormatter();
106 IntlDateFormatter_ce_ptr->create_object = IntlDateFormatter_object_create;
107
108 memcpy(&IntlDateFormatter_handlers, &std_object_handlers,
109 sizeof IntlDateFormatter_handlers);
110 IntlDateFormatter_handlers.offset = XtOffsetOf(IntlDateFormatter_object, zo);
111 IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone;
112 IntlDateFormatter_handlers.free_obj = IntlDateFormatter_object_free;
113 }
114 /* }}} */
115