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 :
29 : /*
30 : * Auxiliary functions needed by objects of 'MessageFormatter' class
31 : */
32 :
33 : /* {{{ MessageFormatter_objects_dtor */
34 : static void MessageFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
35 58 : {
36 58 : zend_objects_destroy_object( object, handle TSRMLS_CC );
37 58 : }
38 : /* }}} */
39 :
40 : /* {{{ MessageFormatter_objects_free */
41 : void MessageFormatter_object_free( zend_object *object TSRMLS_DC )
42 58 : {
43 58 : MessageFormatter_object* mfo = (MessageFormatter_object*)object;
44 :
45 58 : zend_object_std_dtor( &mfo->zo TSRMLS_CC );
46 :
47 58 : msgformat_data_free( &mfo->mf_data TSRMLS_CC );
48 :
49 58 : efree( mfo );
50 58 : }
51 : /* }}} */
52 :
53 : /* {{{ MessageFormatter_object_create */
54 : zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
55 58 : {
56 : zend_object_value retval;
57 : MessageFormatter_object* intern;
58 :
59 58 : intern = ecalloc( 1, sizeof(MessageFormatter_object) );
60 58 : msgformat_data_init( &intern->mf_data TSRMLS_CC );
61 58 : zend_object_std_init( &intern->zo, ce TSRMLS_CC );
62 :
63 58 : retval.handle = zend_objects_store_put(
64 : intern,
65 : MessageFormatter_object_dtor,
66 : (zend_objects_free_object_storage_t)MessageFormatter_object_free,
67 : NULL TSRMLS_CC );
68 :
69 58 : retval.handlers = zend_get_std_object_handlers();
70 :
71 58 : return retval;
72 : }
73 : /* }}} */
74 :
75 : /*
76 : * 'MessageFormatter' class registration structures & functions
77 : */
78 :
79 : /* {{{ arginfo */
80 : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter___construct, 0, 0, 2)
81 : ZEND_ARG_INFO(0, locale)
82 : ZEND_ARG_INFO(0, pattern)
83 : ZEND_END_ARG_INFO()
84 :
85 : ZEND_BEGIN_ARG_INFO(arginfo_messageformatter_geterrormessage, 0)
86 : ZEND_END_ARG_INFO()
87 :
88 : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_formatmessage, 0, 0, 3)
89 : ZEND_ARG_INFO(0, locale)
90 : ZEND_ARG_INFO(0, pattern)
91 : ZEND_ARG_INFO(0, args)
92 : ZEND_END_ARG_INFO()
93 :
94 : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_format, 0, 0, 1)
95 : ZEND_ARG_INFO(0, args)
96 : ZEND_END_ARG_INFO()
97 :
98 : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_setpattern, 0, 0, 1)
99 : ZEND_ARG_INFO(0, pattern)
100 : ZEND_END_ARG_INFO()
101 :
102 : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_parse, 0, 0, 1)
103 : ZEND_ARG_INFO(0, source)
104 : ZEND_END_ARG_INFO()
105 : /* }}} */
106 :
107 : /* {{{ MessageFormatter_class_functions
108 : * Every 'MessageFormatter' class method has an entry in this table
109 : */
110 : static function_entry MessageFormatter_class_functions[] = {
111 : PHP_ME( MessageFormatter, __construct, arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
112 : ZEND_FENTRY( create, ZEND_FN( msgfmt_create ), arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
113 : PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), arginfo_messageformatter_format )
114 : ZEND_FENTRY( formatMessage, ZEND_FN( msgfmt_format_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
115 : PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), arginfo_messageformatter_parse )
116 : ZEND_FENTRY( parseMessage, ZEND_FN( msgfmt_parse_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
117 : PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), arginfo_messageformatter_setpattern )
118 : PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), arginfo_messageformatter_geterrormessage )
119 : PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), arginfo_messageformatter_geterrormessage )
120 : PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), arginfo_messageformatter_geterrormessage )
121 : PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), arginfo_messageformatter_geterrormessage )
122 : { NULL, NULL, NULL }
123 : };
124 : /* }}} */
125 :
126 : /* {{{ msgformat_register_class
127 : * Initialize 'MessageFormatter' class
128 : */
129 : void msgformat_register_class( TSRMLS_D )
130 17633 : {
131 : zend_class_entry ce;
132 :
133 : /* Create and register 'MessageFormatter' class. */
134 17633 : INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions );
135 17633 : ce.create_object = MessageFormatter_object_create;
136 17633 : MessageFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
137 :
138 : /* Declare 'MessageFormatter' class properties. */
139 17633 : if( !MessageFormatter_ce_ptr )
140 : {
141 0 : zend_error(E_ERROR, "Failed to register MessageFormatter class");
142 0 : return;
143 : }
144 : }
145 : /* }}} */
146 :
147 : /*
148 : * Local variables:
149 : * tab-width: 4
150 : * c-basic-offset: 4
151 : * End:
152 : * vim600: noet sw=4 ts=4 fdm=marker
153 : * vim<600: noet sw=4 ts=4
154 : */
|