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 return &intern->zo;
53 }
54 /* }}} */
55
56 /* {{{ MessageFormatter_object_clone */
MessageFormatter_object_clone(zend_object * object)57 zend_object *MessageFormatter_object_clone(zend_object *object)
58 {
59 MessageFormatter_object *mfo, *new_mfo;
60 zend_object *new_obj;
61
62 mfo = php_intl_messageformatter_fetch_object(object);
63 intl_error_reset(INTL_DATA_ERROR_P(mfo));
64
65 new_obj = MessageFormatter_ce_ptr->create_object(object->ce);
66 new_mfo = php_intl_messageformatter_fetch_object(new_obj);
67 /* clone standard parts */
68 zend_objects_clone_members(&new_mfo->zo, &mfo->zo);
69
70 /* clone formatter object */
71 if (MSG_FORMAT_OBJECT(mfo) != NULL) {
72 MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo),
73 &INTL_DATA_ERROR_CODE(mfo));
74
75 if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
76 intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
77 "Failed to clone MessageFormatter object", 0);
78 zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object");
79 }
80 } else {
81 zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter");
82 }
83 return new_obj;
84 }
85 /* }}} */
86
87 /*
88 * 'MessageFormatter' class registration structures & functions
89 */
90
91 /* {{{ msgformat_register_class
92 * Initialize 'MessageFormatter' class
93 */
msgformat_register_class(void)94 void msgformat_register_class( void )
95 {
96 /* Create and register 'MessageFormatter' class. */
97 MessageFormatter_ce_ptr = register_class_MessageFormatter();
98 MessageFormatter_ce_ptr->create_object = MessageFormatter_object_create;
99 MessageFormatter_ce_ptr->default_object_handlers = &MessageFormatter_handlers;
100
101 memcpy(&MessageFormatter_handlers, &std_object_handlers,
102 sizeof MessageFormatter_handlers);
103 MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo);
104 MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone;
105 MessageFormatter_handlers.free_obj = MessageFormatter_object_free;
106 }
107 /* }}} */
108