svn: /pecl/yaf/trunk/ php_yaf.h yaf.c yaf_application.c yaf_loader.c yaf_loader.h
| From: | Xinchen Hui | Date: | Thu, 29 Dec 2011 10:45:11 +0000 |
| Subject: | svn: /pecl/yaf/trunk/ php_yaf.h yaf.c yaf_application.c yaf_loader.c yaf_loader.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-17423@lists.php.net to get a copy of this message | ||
laruence Thu, 29 Dec 2011 10:45:11 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=321501
Log:
Add application.library.namespace configuration for Yaf_Loader
Changed paths:
U pecl/yaf/trunk/php_yaf.h
U pecl/yaf/trunk/yaf.c
U pecl/yaf/trunk/yaf_application.c
U pecl/yaf/trunk/yaf_loader.c
U pecl/yaf/trunk/yaf_loader.h
Modified: pecl/yaf/trunk/php_yaf.h
===================================================================
--- pecl/yaf/trunk/php_yaf.h 2011-12-29 10:38:46 UTC (rev 321500)
+++ pecl/yaf/trunk/php_yaf.h 2011-12-29 10:45:11 UTC (rev 321501)
@@ -82,7 +82,8 @@
char *base_uri;
char *environ;
char *directory;
- char *library_directory;
+ char *local_library;
+ char *local_namespace;
char *global_library;
char *view_ext;
char *default_module;
Modified: pecl/yaf/trunk/yaf.c
===================================================================
--- pecl/yaf/trunk/yaf.c 2011-12-29 10:38:46 UTC (rev 321500)
+++ pecl/yaf/trunk/yaf.c 2011-12-29 10:45:11 UTC (rev 321501)
@@ -82,7 +82,7 @@
yaf_globals->autoload_started = 0;
yaf_globals->configs = NULL;
yaf_globals->directory = NULL;
- yaf_globals->library_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;
@@ -183,7 +183,8 @@
YAF_G(catch_exception) = 0;
YAF_G(directory) = NULL;
YAF_G(bootstrap) = NULL;
- YAF_G(library_directory) = NULL;
+ YAF_G(local_library) = NULL;
+ YAF_G(local_namespace) = NULL;
YAF_G(modules) = NULL;
YAF_G(base_uri) = NULL;
#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4))
@@ -202,8 +203,31 @@
{
if (YAF_G(directory)) {
efree(YAF_G(directory));
- YAF_G(directory) = NULL;
}
+ if (YAF_G(local_library)) {
+ efree(YAF_G(local_library));
+ }
+ if (YAF_G(local_namespace)) {
+ efree(YAF_G(local_namespace));
+ }
+ if (YAF_G(bootstrap)) {
+ efree(YAF_G(bootstrap));
+ }
+ if (YAF_G(modules)) {
+ zval_dtor(YAF_G(modules));
+ efree(YAF_G(modules));
+ }
+ if (YAF_G(base_uri)) {
+ efree(YAF_G(base_uri));
+ }
+#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4))
+ if (YAF_G(buffer)) {
+ efree(YAF_G(buffer));
+ }
+ if (YAF_G(owrite_handler)) {
+ efree(YAF_G(owrite_handler));
+ }
+#endif
return SUCCESS;
}
Modified: pecl/yaf/trunk/yaf_application.c
===================================================================
--- pecl/yaf/trunk/yaf_application.c 2011-12-29 10:38:46 UTC (rev 321500)
+++ pecl/yaf/trunk/yaf_application.c 2011-12-29 10:45:11 UTC (rev 321501)
@@ -157,12 +157,22 @@
YAF_G(bootstrap) = estrndup(Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval));
}
- if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("library"), (void **)&ppzval) ==
SUCCESS
- && Z_TYPE_PP(ppzval) == IS_STRING) {
- YAF_G(library_directory) = estrndup(Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval));
+ if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("library"), (void **)&ppzval) ==
SUCCESS) {
+ if (IS_STRING == Z_TYPE_PP(ppzval)) {
+ YAF_G(local_library) = estrndup(Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval));
+ } else if (IS_ARRAY == Z_TYPE_PP(ppzval)) {
+ if (zend_hash_find(Z_ARRVAL_PP(ppzval), ZEND_STRS("directory"), (void **)&ppsval)
== SUCCESS
+ && Z_TYPE_PP(ppsval) == IS_STRING) {
+ YAF_G(local_library) = estrndup(Z_STRVAL_PP(ppsval), Z_STRLEN_PP(ppsval));
+ }
+ if (zend_hash_find(Z_ARRVAL_PP(ppzval), ZEND_STRS("namespace"), (void **)&ppsval)
== SUCCESS
+ && Z_TYPE_PP(ppsval) == IS_STRING) {
+ YAF_G(local_namespace) = estrndup(Z_STRVAL_PP(ppsval), Z_STRLEN_PP(ppsval));
+ }
+ }
}
- if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("view"), (void **)&ppzval) == FAILURE
+ if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("view"), (void **)&ppzval) == FAILURE
|| Z_TYPE_PP(ppzval) != IS_ARRAY) {
YAF_G(view_ext) = YAF_DEFAULT_VIEW_EXT;
} else {
@@ -332,17 +342,17 @@
zval_ptr_dtor(&zdispatcher);
zval_ptr_dtor(&zconfig);
- if (YAF_G(library_directory)) {
- loader = yaf_loader_instance(NULL, YAF_G(library_directory),
+ if (YAF_G(local_library)) {
+ loader = yaf_loader_instance(NULL, YAF_G(local_library),
strlen(YAF_G(global_library))? YAF_G(global_library) : NULL TSRMLS_CC);
- efree(YAF_G(library_directory));
- YAF_G(library_directory) = NULL;
+ efree(YAF_G(local_library));
+ YAF_G(local_library) = NULL;
} else {
- char *library_directory;
- spprintf(&library_directory, 0, "%s%c%s", YAF_G(directory), DEFAULT_SLASH,
YAF_LIBRARY_DIRECTORY_NAME);
- loader = yaf_loader_instance(NULL, library_directory,
+ char *local_library;
+ spprintf(&local_library, 0, "%s%c%s", YAF_G(directory), DEFAULT_SLASH,
YAF_LIBRARY_DIRECTORY_NAME);
+ loader = yaf_loader_instance(NULL, local_library,
strlen(YAF_G(global_library))? YAF_G(global_library) : NULL TSRMLS_CC);
- efree(library_directory);
+ efree(local_library);
}
if (!loader) {
@@ -350,6 +360,22 @@
RETURN_FALSE;
}
+ if (YAF_G(local_namespace)) {
+ uint i, len;
+ char *tmp = YAF_G(local_namespace);
+ len = strlen(tmp);
+ if (len) {
+ for(i=0; i<len; i++) {
+ if (tmp[i] == ',' || tmp[i] == ' ') {
+ tmp[i] = DEFAULT_DIR_SEPARATOR;
+ }
+ }
+ yaf_loader_register_namespace_single(loader, tmp, len TSRMLS_CC);
+ }
+ efree(YAF_G(local_namespace));
+ YAF_G(local_namespace) = NULL;
+ }
+
zend_update_property_bool(yaf_application_ce, self, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_RUN),
0 TSRMLS_CC);
zend_update_property_string(yaf_application_ce, self,
ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ENV), YAF_G(environ) TSRMLS_CC);
Modified: pecl/yaf/trunk/yaf_loader.c
===================================================================
--- pecl/yaf/trunk/yaf_loader.c 2011-12-29 10:38:46 UTC (rev 321500)
+++ pecl/yaf/trunk/yaf_loader.c 2011-12-29 10:45:11 UTC (rev 321501)
@@ -516,9 +516,9 @@
}
/* }}} */
-/** {{{ int yaf_loader_register_namespace_single(yaf_loader_t *loader, zval *prefix TSRMLS_DC)
+/** {{{ int yaf_loader_register_namespace_single(yaf_loader_t *loader, char *prefix, uint len
TSRMLS_DC)
*/
-int yaf_loader_register_namespace_single(yaf_loader_t *loader, zval *prefix TSRMLS_DC) {
+int yaf_loader_register_namespace_single(yaf_loader_t *loader, char *prefix, uint len TSRMLS_DC) {
zval *namespaces;
smart_str buf = {NULL, 0, 0};
@@ -530,7 +530,7 @@
smart_str_appendl(&buf, Z_STRVAL_P(namespaces), Z_STRLEN_P(namespaces));
}
- smart_str_appendl(&buf, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix));
+ smart_str_appendl(&buf, prefix, len);
smart_str_appendc(&buf, DEFAULT_DIR_SEPARATOR);
ZVAL_STRINGL(namespaces, buf.c, buf.len, 1);
@@ -611,7 +611,7 @@
}
if (IS_STRING == Z_TYPE_P(namespaces)) {
- if (yaf_loader_register_namespace_single(getThis(), namespaces TSRMLS_CC)) {
+ if (yaf_loader_register_namespace_single(getThis(), Z_STRVAL_P(namespaces),
Z_STRLEN_P(namespaces) TSRMLS_CC)) {
RETURN_ZVAL(getThis(), 1, 0);
}
} else if (IS_ARRAY == Z_TYPE_P(namespaces)) {
Modified: pecl/yaf/trunk/yaf_loader.h
===================================================================
--- pecl/yaf/trunk/yaf_loader.h 2011-12-29 10:38:46 UTC (rev 321500)
+++ pecl/yaf/trunk/yaf_loader.h 2011-12-29 10:45:11 UTC (rev 321501)
@@ -90,6 +90,7 @@
int yaf_loader_import(char *path, int len, int use_path TSRMLS_DC);
int yaf_loader_compose(char *path, int len, int use_path TSRMLS_DC);
int yaf_register_autoloader(yaf_loader_t *loader TSRMLS_DC);
+int yaf_loader_register_namespace_single(yaf_loader_t *loader, char *prefix, uint len TSRMLS_DC);
yaf_loader_t * yaf_loader_instance(yaf_loader_t *this_ptr, char *library_path, char *global_path
TSRMLS_DC);
extern PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int
mode TSRMLS_DC);