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: Stanislav Malyshev <stas@zend.com> |
12 +----------------------------------------------------------------------+
13 */
14
15 #include <unicode/unum.h>
16
17 #include "msgformat_class.h"
18 #include "php_intl.h"
19 #include "msgformat_data.h"
20 #include "msgformat_arginfo.h"
21
22 #include <zend_exceptions.h>
23
24 zend_class_entry *MessageFormatter_ce_ptr = NULL;
25 static zend_object_handlers MessageFormatter_handlers;
26
27 /*
28 * Auxiliary functions needed by objects of 'MessageFormatter' class
29 */
30
31 /* {{{ MessageFormatter_objects_free */
MessageFormatter_object_free(zend_object * object)32 void MessageFormatter_object_free( zend_object *object )
33 {
34 MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object);
35
36 zend_object_std_dtor( &mfo->zo );
37
38 msgformat_data_free( &mfo->mf_data );
39 }
40 /* }}} */
41
42 /* {{{ MessageFormatter_object_create */
MessageFormatter_object_create(zend_class_entry * ce)43 zend_object *MessageFormatter_object_create(zend_class_entry *ce)
44 {
45 MessageFormatter_object* intern;
46
47 intern = zend_object_alloc(sizeof(MessageFormatter_object), ce);
48 msgformat_data_init( &intern->mf_data );
49 zend_object_std_init( &intern->zo, ce );
50 object_properties_init(&intern->zo, ce);
51
52 intern->zo.handlers = &MessageFormatter_handlers;
53
54 return &intern->zo;
55 }
56 /* }}} */
57
58 /* {{{ MessageFormatter_object_clone */
MessageFormatter_object_clone(zend_object * object)59 zend_object *MessageFormatter_object_clone(zend_object *object)
60 {
61 MessageFormatter_object *mfo, *new_mfo;
62 zend_object *new_obj;
63
64 mfo = php_intl_messageformatter_fetch_object(object);
65 intl_error_reset(INTL_DATA_ERROR_P(mfo));
66
67 new_obj = MessageFormatter_ce_ptr->create_object(object->ce);
68 new_mfo = php_intl_messageformatter_fetch_object(new_obj);
69 /* clone standard parts */
70 zend_objects_clone_members(&new_mfo->zo, &mfo->zo);
71
72 /* clone formatter object */
73 if (MSG_FORMAT_OBJECT(mfo) != NULL) {
74 MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo),
75 &INTL_DATA_ERROR_CODE(mfo));
76
77 if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
78 intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
79 "Failed to clone MessageFormatter object", 0);
80 zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object");
81 }
82 } else {
83 zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter");
84 }
85 return new_obj;
86 }
87 /* }}} */
88
89 /*
90 * 'MessageFormatter' class registration structures & functions
91 */
92
93 /* {{{ msgformat_register_class
94 * Initialize 'MessageFormatter' class
95 */
msgformat_register_class(void)96 void msgformat_register_class( void )
97 {
98 /* Create and register 'MessageFormatter' class. */
99 MessageFormatter_ce_ptr = register_class_MessageFormatter();
100 MessageFormatter_ce_ptr->create_object = MessageFormatter_object_create;
101
102 memcpy(&MessageFormatter_handlers, &std_object_handlers,
103 sizeof MessageFormatter_handlers);
104 MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo);
105 MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone;
106 MessageFormatter_handlers.free_obj = MessageFormatter_object_free;
107 }
108 /* }}} */
109