forked from laruence/yaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaf.c
316 lines (283 loc) · 9.88 KB
/
yaf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
+----------------------------------------------------------------------+
| Yet Another Framework |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Xinchen Hui <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id: yaf.c 329002 2013-01-07 12:55:53Z laruence $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "main/SAPI.h"
#include "Zend/zend_alloc.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "php_yaf.h"
#include "yaf_logo.h"
#include "yaf_loader.h"
#include "yaf_exception.h"
#include "yaf_application.h"
#include "yaf_dispatcher.h"
#include "yaf_config.h"
#include "yaf_view.h"
#include "yaf_controller.h"
#include "yaf_action.h"
#include "yaf_request.h"
#include "yaf_response.h"
#include "yaf_router.h"
#include "yaf_bootstrap.h"
#include "yaf_plugin.h"
#include "yaf_registry.h"
#include "yaf_session.h"
ZEND_DECLARE_MODULE_GLOBALS(yaf);
/* {{{ yaf_functions[]
*/
zend_function_entry yaf_functions[] = {
{NULL, NULL, NULL}
};
/* }}} */
/** {{{ PHP_INI_MH(OnUpdateSeparator)
*/
PHP_INI_MH(OnUpdateSeparator) {
YAF_G(name_separator) = new_value;
YAF_G(name_separator_len) = new_value_length;
return SUCCESS;
}
/* }}} */
/** {{{ PHP_INI
*/
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("yaf.library", "", PHP_INI_ALL, OnUpdateString, global_library, zend_yaf_globals, yaf_globals)
STD_PHP_INI_BOOLEAN("yaf.action_prefer", "0", PHP_INI_ALL, OnUpdateBool, action_prefer, zend_yaf_globals, yaf_globals)
STD_PHP_INI_BOOLEAN("yaf.lowcase_path", "0", PHP_INI_ALL, OnUpdateBool, lowcase_path, zend_yaf_globals, yaf_globals)
STD_PHP_INI_BOOLEAN("yaf.use_spl_autoload", "0", PHP_INI_ALL, OnUpdateBool, use_spl_autoload, zend_yaf_globals, yaf_globals)
STD_PHP_INI_ENTRY("yaf.forward_limit", "5", PHP_INI_ALL, OnUpdateLongGEZero, forward_limit, zend_yaf_globals, yaf_globals)
STD_PHP_INI_BOOLEAN("yaf.name_suffix", "1", PHP_INI_ALL, OnUpdateBool, name_suffix, zend_yaf_globals, yaf_globals)
PHP_INI_ENTRY("yaf.name_separator", "", PHP_INI_ALL, OnUpdateSeparator)
STD_PHP_INI_BOOLEAN("yaf.cache_config", "0", PHP_INI_SYSTEM, OnUpdateBool, cache_config, zend_yaf_globals, yaf_globals)
/* {{{ This only effects internally */
STD_PHP_INI_BOOLEAN("yaf.st_compatible", "0", PHP_INI_ALL, OnUpdateBool, st_compatible, zend_yaf_globals, yaf_globals)
/* }}} */
STD_PHP_INI_ENTRY("yaf.environ", "product", PHP_INI_SYSTEM, OnUpdateString, environ, zend_yaf_globals, yaf_globals)
#ifdef YAF_HAVE_NAMESPACE
STD_PHP_INI_BOOLEAN("yaf.use_namespace", "0", PHP_INI_SYSTEM, OnUpdateBool, use_namespace, zend_yaf_globals, yaf_globals)
#endif
PHP_INI_END();
/* }}} */
/** {{{ PHP_GINIT_FUNCTION
*/
PHP_GINIT_FUNCTION(yaf)
{
yaf_globals->autoload_started = 0;
yaf_globals->configs = NULL;
yaf_globals->directory = NULL;
yaf_globals->local_library = NULL;
yaf_globals->ext = YAF_DEFAULT_EXT;
yaf_globals->view_ext = YAF_DEFAULT_VIEW_EXT;
yaf_globals->default_module = YAF_ROUTER_DEFAULT_MODULE;
yaf_globals->default_controller = YAF_ROUTER_DEFAULT_CONTROLLER;
yaf_globals->default_action = YAF_ROUTER_DEFAULT_ACTION;
yaf_globals->bootstrap = YAF_DEFAULT_BOOTSTRAP;
yaf_globals->modules = NULL;
yaf_globals->default_route = NULL;
yaf_globals->suppressing_warning = 0;
}
/* }}} */
/** {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(yaf)
{
REGISTER_INI_ENTRIES();
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5
php_register_info_logo(YAF_LOGO_GUID, YAF_LOGO_MIME_TYPE, yaf_logo, sizeof(yaf_logo));
#endif
#ifdef YAF_HAVE_NAMESPACE
if(YAF_G(use_namespace)) {
REGISTER_STRINGL_CONSTANT("YAF\\VERSION", PHP_YAF_VERSION, sizeof(PHP_YAF_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("YAF\\ENVIRON", YAF_G(environ), strlen(YAF_G(environ)), CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\STARTUP_FAILED", YAF_ERR_STARTUP_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\ROUTE_FAILED", YAF_ERR_ROUTE_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\DISPATCH_FAILED", YAF_ERR_DISPATCH_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\AUTOLOAD_FAILED", YAF_ERR_AUTOLOAD_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\NOTFOUND\\MODULE", YAF_ERR_NOTFOUND_MODULE, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\NOTFOUND\\CONTROLLER",YAF_ERR_NOTFOUND_CONTROLLER, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\NOTFOUND\\ACTION", YAF_ERR_NOTFOUND_ACTION, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\NOTFOUND\\VIEW", YAF_ERR_NOTFOUND_VIEW, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\CALL_FAILED", YAF_ERR_CALL_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF\\ERR\\TYPE_ERROR", YAF_ERR_TYPE_ERROR, CONST_PERSISTENT | CONST_CS);
} else {
#endif
REGISTER_STRINGL_CONSTANT("YAF_VERSION", PHP_YAF_VERSION, sizeof(PHP_YAF_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("YAF_ENVIRON", YAF_G(environ),strlen(YAF_G(environ)), CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_STARTUP_FAILED", YAF_ERR_STARTUP_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_ROUTE_FAILED", YAF_ERR_ROUTE_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_DISPATCH_FAILED", YAF_ERR_DISPATCH_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_AUTOLOAD_FAILED", YAF_ERR_AUTOLOAD_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_NOTFOUND_MODULE", YAF_ERR_NOTFOUND_MODULE, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_NOTFOUND_CONTROLLER", YAF_ERR_NOTFOUND_CONTROLLER, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_NOTFOUND_ACTION", YAF_ERR_NOTFOUND_ACTION, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_NOTFOUND_VIEW", YAF_ERR_NOTFOUND_VIEW, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_CALL_FAILED", YAF_ERR_CALL_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("YAF_ERR_TYPE_ERROR", YAF_ERR_TYPE_ERROR, CONST_PERSISTENT | CONST_CS);
#ifdef YAF_HAVE_NAMESPACE
}
#endif
/* startup components */
YAF_STARTUP(application);
YAF_STARTUP(bootstrap);
YAF_STARTUP(dispatcher);
YAF_STARTUP(loader);
YAF_STARTUP(request);
YAF_STARTUP(response);
YAF_STARTUP(controller);
YAF_STARTUP(action);
YAF_STARTUP(config);
YAF_STARTUP(view);
YAF_STARTUP(router);
YAF_STARTUP(plugin);
YAF_STARTUP(registry);
YAF_STARTUP(session);
YAF_STARTUP(exception);
return SUCCESS;
}
/* }}} */
/** {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(yaf)
{
UNREGISTER_INI_ENTRIES();
if (YAF_G(configs)) {
zend_hash_destroy(YAF_G(configs));
pefree(YAF_G(configs), 1);
}
return SUCCESS;
}
/* }}} */
/** {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(yaf)
{
YAF_G(running) = 0;
YAF_G(in_exception) = 0;
YAF_G(throw_exception) = 1;
YAF_G(catch_exception) = 0;
YAF_G(directory) = NULL;
YAF_G(bootstrap) = NULL;
YAF_G(local_library) = NULL;
YAF_G(local_namespaces) = NULL;
YAF_G(modules) = NULL;
YAF_G(base_uri) = NULL;
YAF_G(view_directory) = NULL;
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4))
YAF_G(buffer) = NULL;
YAF_G(owrite_handler) = NULL;
YAF_G(buf_nesting) = 0;
#endif
return SUCCESS;
}
/* }}} */
/** {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(yaf)
{
if (YAF_G(directory)) {
efree(YAF_G(directory));
}
if (YAF_G(local_library)) {
efree(YAF_G(local_library));
}
if (YAF_G(local_namespaces)) {
efree(YAF_G(local_namespaces));
}
if (YAF_G(bootstrap)) {
efree(YAF_G(bootstrap));
}
if (YAF_G(modules)) {
zval_ptr_dtor(&(YAF_G(modules)));
}
if (YAF_G(base_uri)) {
efree(YAF_G(base_uri));
}
if (YAF_G(view_directory)) {
efree(YAF_G(view_directory));
}
YAF_G(default_route) = NULL;
return SUCCESS;
}
/* }}} */
/** {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(yaf)
{
php_info_print_table_start();
if (PG(expose_php) && !sapi_module.phpinfo_as_text) {
php_info_print_table_header(2, "yaf support", YAF_LOGO_IMG"enabled");
} else {
php_info_print_table_header(2, "yaf support", "enabled");
}
php_info_print_table_row(2, "Version", PHP_YAF_VERSION);
php_info_print_table_row(2, "Supports", YAF_SUPPORT_URL);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
/** {{{ DL support
*/
#ifdef COMPILE_DL_YAF
ZEND_GET_MODULE(yaf)
#endif
/* }}} */
/** {{{ module depends
*/
#if ZEND_MODULE_API_NO >= 20050922
zend_module_dep yaf_deps[] = {
ZEND_MOD_REQUIRED("spl")
ZEND_MOD_REQUIRED("pcre")
ZEND_MOD_OPTIONAL("session")
{NULL, NULL, NULL}
};
#endif
/* }}} */
/** {{{ yaf_module_entry
*/
zend_module_entry yaf_module_entry = {
#if ZEND_MODULE_API_NO >= 20050922
STANDARD_MODULE_HEADER_EX, NULL,
yaf_deps,
#else
STANDARD_MODULE_HEADER,
#endif
"yaf",
yaf_functions,
PHP_MINIT(yaf),
PHP_MSHUTDOWN(yaf),
PHP_RINIT(yaf),
PHP_RSHUTDOWN(yaf),
PHP_MINFO(yaf),
PHP_YAF_VERSION,
PHP_MODULE_GLOBALS(yaf),
PHP_GINIT(yaf),
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/