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 return &intern->zo;
61 }
62 /* }}} */
63
64 /* {{{ IntlDateFormatter_object_clone */
IntlDateFormatter_object_clone(zend_object * object)65 zend_object *IntlDateFormatter_object_clone(zend_object *object)
66 {
67 IntlDateFormatter_object *dfo = php_intl_dateformatter_fetch_object(object);
68 zend_object *new_obj = IntlDateFormatter_ce_ptr->create_object(object->ce);
69 IntlDateFormatter_object *new_dfo = php_intl_dateformatter_fetch_object(new_obj);
70
71 /* clone standard parts */
72 zend_objects_clone_members(&new_dfo->zo, &dfo->zo);
73
74 /* clone formatter object */
75 if (DATE_FORMAT_OBJECT(dfo) != NULL) {
76 UErrorCode error = U_ZERO_ERROR;
77 DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &error);
78
79 if (U_FAILURE(error)) {
80 zend_throw_error(NULL, "Failed to clone IntlDateFormatter");
81 }
82 } else {
83 zend_throw_error(NULL, "Cannot clone uninitialized IntlDateFormatter");
84 }
85 return new_obj;
86 }
87 /* }}} */
88
89 /*
90 * 'IntlDateFormatter' class registration structures & functions
91 */
92
93 /* {{{ dateformat_register_class
94 * Initialize 'IntlDateFormatter' class
95 */
dateformat_register_IntlDateFormatter_class(void)96 void dateformat_register_IntlDateFormatter_class( void )
97 {
98 /* Create and register 'IntlDateFormatter' class. */
99 IntlDateFormatter_ce_ptr = register_class_IntlDateFormatter();
100 IntlDateFormatter_ce_ptr->create_object = IntlDateFormatter_object_create;
101 IntlDateFormatter_ce_ptr->default_object_handlers = &IntlDateFormatter_handlers;
102
103 memcpy(&IntlDateFormatter_handlers, &std_object_handlers,
104 sizeof IntlDateFormatter_handlers);
105 IntlDateFormatter_handlers.offset = XtOffsetOf(IntlDateFormatter_object, zo);
106 IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone;
107 IntlDateFormatter_handlers.free_obj = IntlDateFormatter_object_free;
108 }
109 /* }}} */
110