Annotation of embedaddon/php/ext/intl/msgformat/msgformat_class.c, revision 1.1.1.2
1.1 misho 1: /*
2: +----------------------------------------------------------------------+
3: | PHP Version 5 |
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: Stanislav Malyshev <stas@zend.com> |
14: +----------------------------------------------------------------------+
15: */
16:
17: #include <unicode/unum.h>
18:
19: #include "msgformat_class.h"
20: #include "php_intl.h"
21: #include "msgformat_data.h"
22: #include "msgformat_format.h"
23: #include "msgformat_parse.h"
24: #include "msgformat.h"
25: #include "msgformat_attr.h"
26:
27: zend_class_entry *MessageFormatter_ce_ptr = NULL;
28: static zend_object_handlers MessageFormatter_handlers;
29:
30: /*
31: * Auxiliary functions needed by objects of 'MessageFormatter' class
32: */
33:
34: /* {{{ MessageFormatter_objects_dtor */
35: static void MessageFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
36: {
37: zend_objects_destroy_object( object, handle TSRMLS_CC );
38: }
39: /* }}} */
40:
41: /* {{{ MessageFormatter_objects_free */
42: void MessageFormatter_object_free( zend_object *object TSRMLS_DC )
43: {
44: MessageFormatter_object* mfo = (MessageFormatter_object*)object;
45:
46: zend_object_std_dtor( &mfo->zo TSRMLS_CC );
47:
48: msgformat_data_free( &mfo->mf_data TSRMLS_CC );
49:
50: efree( mfo );
51: }
52: /* }}} */
53:
54: /* {{{ MessageFormatter_object_create */
55: zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
56: {
57: zend_object_value retval;
58: MessageFormatter_object* intern;
59:
60: intern = ecalloc( 1, sizeof(MessageFormatter_object) );
61: msgformat_data_init( &intern->mf_data TSRMLS_CC );
62: zend_object_std_init( &intern->zo, ce TSRMLS_CC );
63:
64: retval.handle = zend_objects_store_put(
65: intern,
66: MessageFormatter_object_dtor,
67: (zend_objects_free_object_storage_t)MessageFormatter_object_free,
68: NULL TSRMLS_CC );
69:
70: retval.handlers = &MessageFormatter_handlers;
71:
72: return retval;
73: }
74: /* }}} */
75:
76: /* {{{ MessageFormatter_object_clone */
77: zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC)
78: {
79: zend_object_value new_obj_val;
80: zend_object_handle handle = Z_OBJ_HANDLE_P(object);
81: MessageFormatter_object *mfo, *new_mfo;
82:
83: MSG_FORMAT_METHOD_FETCH_OBJECT;
84: new_obj_val = MessageFormatter_ce_ptr->create_object(MessageFormatter_ce_ptr TSRMLS_CC);
85: new_mfo = (MessageFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
86: /* clone standard parts */
87: zend_objects_clone_members(&new_mfo->zo, new_obj_val, &mfo->zo, handle TSRMLS_CC);
88: /* clone formatter object */
89: MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo), &INTL_DATA_ERROR_CODE(new_mfo));
90: if(U_FAILURE(INTL_DATA_ERROR_CODE(new_mfo))) {
91: /* set up error in case error handler is interested */
92: intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_mfo), "Failed to clone MessageFormatter object", 0 TSRMLS_CC );
93: MessageFormatter_object_dtor(new_mfo, new_obj_val.handle TSRMLS_CC); /* free new object */
94: zend_error(E_ERROR, "Failed to clone MessageFormatter object");
95: }
96: return new_obj_val;
97: }
98: /* }}} */
99:
100: /*
101: * 'MessageFormatter' class registration structures & functions
102: */
103:
104: /* {{{ arginfo */
105: ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter___construct, 0, 0, 2)
106: ZEND_ARG_INFO(0, locale)
107: ZEND_ARG_INFO(0, pattern)
108: ZEND_END_ARG_INFO()
109:
110: ZEND_BEGIN_ARG_INFO(arginfo_messageformatter_geterrormessage, 0)
111: ZEND_END_ARG_INFO()
112:
113: ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_formatmessage, 0, 0, 3)
114: ZEND_ARG_INFO(0, locale)
115: ZEND_ARG_INFO(0, pattern)
116: ZEND_ARG_INFO(0, args)
117: ZEND_END_ARG_INFO()
118:
119: ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_format, 0, 0, 1)
120: ZEND_ARG_INFO(0, args)
121: ZEND_END_ARG_INFO()
122:
123: ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_setpattern, 0, 0, 1)
124: ZEND_ARG_INFO(0, pattern)
125: ZEND_END_ARG_INFO()
126:
127: ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_parse, 0, 0, 1)
128: ZEND_ARG_INFO(0, source)
129: ZEND_END_ARG_INFO()
130: /* }}} */
131:
132: /* {{{ MessageFormatter_class_functions
133: * Every 'MessageFormatter' class method has an entry in this table
134: */
1.1.1.2 ! misho 135: static zend_function_entry MessageFormatter_class_functions[] = {
1.1 misho 136: PHP_ME( MessageFormatter, __construct, arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
137: ZEND_FENTRY( create, ZEND_FN( msgfmt_create ), arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
138: PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), arginfo_messageformatter_format )
139: ZEND_FENTRY( formatMessage, ZEND_FN( msgfmt_format_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
140: PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), arginfo_messageformatter_parse )
141: ZEND_FENTRY( parseMessage, ZEND_FN( msgfmt_parse_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
142: PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), arginfo_messageformatter_setpattern )
143: PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), arginfo_messageformatter_geterrormessage )
144: PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), arginfo_messageformatter_geterrormessage )
145: PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), arginfo_messageformatter_geterrormessage )
146: PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), arginfo_messageformatter_geterrormessage )
147: PHP_FE_END
148: };
149: /* }}} */
150:
151: /* {{{ msgformat_register_class
152: * Initialize 'MessageFormatter' class
153: */
154: void msgformat_register_class( TSRMLS_D )
155: {
156: zend_class_entry ce;
157:
158: /* Create and register 'MessageFormatter' class. */
159: INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions );
160: ce.create_object = MessageFormatter_object_create;
161: MessageFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
162:
163: memcpy(&MessageFormatter_handlers, zend_get_std_object_handlers(),
164: sizeof MessageFormatter_handlers);
165: MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone;
166:
167: /* Declare 'MessageFormatter' class properties. */
168: if( !MessageFormatter_ce_ptr )
169: {
170: zend_error(E_ERROR, "Failed to register MessageFormatter class");
171: return;
172: }
173: }
174: /* }}} */
175:
176: /*
177: * Local variables:
178: * tab-width: 4
179: * c-basic-offset: 4
180: * End:
181: * vim600: noet sw=4 ts=4 fdm=marker
182: * vim<600: noet sw=4 ts=4
183: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>