This source file includes following definitions.
- msgfmt_ctor
- PHP_FUNCTION
- PHP_METHOD
- PHP_FUNCTION
- PHP_FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <unicode/ustring.h>
22 #include <unicode/umsg.h>
23
24 #include "php_intl.h"
25 #include "msgformat_class.h"
26 #include "intl_convert.h"
27
28
29 static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
30 {
31 const char* locale;
32 char* pattern;
33 int locale_len = 0, pattern_len = 0;
34 UChar* spattern = NULL;
35 int spattern_len = 0;
36 zval* object;
37 MessageFormatter_object* mfo;
38 intl_error_reset( NULL TSRMLS_CC );
39
40 object = return_value;
41
42 if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss",
43 &locale, &locale_len, &pattern, &pattern_len ) == FAILURE )
44 {
45 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
46 "msgfmt_create: unable to parse input parameters", 0 TSRMLS_CC );
47 zval_dtor(return_value);
48 RETURN_NULL();
49 }
50
51 INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
52 MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
53
54
55 if(pattern && pattern_len) {
56 intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
57 INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16");
58 } else {
59 spattern_len = 0;
60 spattern = NULL;
61 }
62
63 if(locale_len == 0) {
64 locale = intl_locale_get_default(TSRMLS_C);
65 }
66
67 #ifdef MSG_FORMAT_QUOTE_APOS
68 if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
69 INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format");
70 }
71 #endif
72
73 if ((mfo)->mf_data.orig_format) {
74 msgformat_data_free(&mfo->mf_data TSRMLS_CC);
75 }
76
77 (mfo)->mf_data.orig_format = estrndup(pattern, pattern_len);
78 (mfo)->mf_data.orig_format_len = pattern_len;
79
80
81 MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(mfo));
82
83 if(spattern) {
84 efree(spattern);
85 }
86
87 INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed");
88 }
89
90
91
92
93
94
95
96 PHP_FUNCTION( msgfmt_create )
97 {
98 object_init_ex( return_value, MessageFormatter_ce_ptr );
99 msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
100 }
101
102
103
104
105
106 PHP_METHOD( MessageFormatter, __construct )
107 {
108 return_value = getThis();
109 msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
110 }
111
112
113
114
115
116
117
118 PHP_FUNCTION( msgfmt_get_error_code )
119 {
120 zval* object = NULL;
121 MessageFormatter_object* mfo = NULL;
122
123
124 if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
125 &object, MessageFormatter_ce_ptr ) == FAILURE )
126 {
127 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
128 "msgfmt_get_error_code: unable to parse input params", 0 TSRMLS_CC );
129
130 RETURN_FALSE;
131 }
132
133 mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
134
135
136 RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) );
137 }
138
139
140
141
142
143
144
145 PHP_FUNCTION( msgfmt_get_error_message )
146 {
147 char* message = NULL;
148 zval* object = NULL;
149 MessageFormatter_object* mfo = NULL;
150
151
152 if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
153 &object, MessageFormatter_ce_ptr ) == FAILURE )
154 {
155 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
156 "msgfmt_get_error_message: unable to parse input params", 0 TSRMLS_CC );
157
158 RETURN_FALSE;
159 }
160
161 mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
162
163
164 message = intl_error_get_message( &mfo->mf_data.error TSRMLS_CC );
165 RETURN_STRING( message, 0);
166 }
167
168
169
170
171
172
173
174
175
176