diff --git a/package.xml b/package.xml
index fdda49b3..c8d0b60b 100644
--- a/package.xml
+++ b/package.xml
@@ -25,6 +25,7 @@
- Added Yaf_Request::cleanParams()
- Added Yaf_Controller::getName(), Yaf_Action::getControllerName()
- Added Yaf_Dispatcher::getDefaultModule(), Yaf_Dispatcher::getDefaultController() and Yaf_Dispatcher::getDefaultAction()
+ - Added Yaf_Application::getInstance(), which is alias of Yaf_Application:app()
- Rmoved all lead underline for fake protected property name(examing by var_dump)
- Fixed bug that protected method of Bootstrap get executed
- Yaf_View_Simple is final class now, custom view engin should implements Yaf_View_Interface
@@ -214,6 +215,7 @@
+
diff --git a/tests/014.phpt b/tests/014.phpt
index 8b6cee8d..3688fbfa 100644
--- a/tests/014.phpt
+++ b/tests/014.phpt
@@ -32,6 +32,45 @@ Yaf_Application Object
[dispatcher:protected] => Yaf_Dispatcher Object
(
+ [auto_render:protected] => 1
+ [instant_flush:protected] =>
+ [return_response:protected] =>
+ [request:protected] => Yaf_Request_Http Object
+ (
+ [method] => CLI
+ [module] =>
+ [controller] =>
+ [action] =>
+ [uri:protected] =>
+ [base_uri:protected] =>
+ [dispatched:protected] =>
+ [routed:protected] =>
+ [language:protected] =>
+ [params:protected] => Array
+ (
+ )
+
+ )
+
+ [response:protected] =>
+ [router:protected] => Yaf_Router Object
+ (
+ [routes:protected] => Array
+ (
+ [_default] => Yaf_Route_Static Object
+ (
+ )
+
+ )
+
+ [current:protected] =>
+ )
+
+ [view:protected] =>
+ [plugins:protected] => Array
+ (
+ )
+
)
[modules:protected] => Array
diff --git a/tests/095.phpt b/tests/095.phpt
index 6bf5a2d3..e5535390 100644
--- a/tests/095.phpt
+++ b/tests/095.phpt
@@ -125,6 +125,7 @@ object(Yaf_Application)#1 (13) {
}
["dispatcher:protected"]=>
object(Yaf_Dispatcher)#%d (%d) {
+%A
}
["modules:protected"]=>
array(1) {
diff --git a/tests/101.phpt b/tests/101.phpt
new file mode 100644
index 00000000..6afe6777
--- /dev/null
+++ b/tests/101.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Check for various cycle references
+--SKIPIF--
+
+--INI--
+yaf.use_spl_autoload=0
+yaf.lowcase_path=0
+yaf.use_namespace=0
+--FILE--
+request = new Yaf_Request_Simple();
+$foo->request->setParam("foo", $foo);
+unset($foo);
+
+$foo = new Stdclass();
+$foo->config = new Yaf_Config_Simple(array(), 0);
+$foo->config->foo = $foo;
+unset($foo);
+
+$foo = new Stdclass();
+$foo->request = new Yaf_Request_Simple();
+$app = new Yaf_Application(["yaf" => ["directory" => __DIR__]]);
+$app->getDispatcher()->setRequest($foo->request);
+unset($foo);
+?>
+okey
+--EXPECT--
+okey
diff --git a/yaf_application.c b/yaf_application.c
index 81ba7879..5f3fae63 100644
--- a/yaf_application.c
+++ b/yaf_application.c
@@ -78,6 +78,80 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_application_setappdir_arginfo, 0, 0, 1)
ZEND_END_ARG_INFO()
/* }}} */
+static zend_object* yaf_application_new(zend_class_entry *ce) /* {{{ */ {
+ yaf_application_object *app = emalloc(sizeof(yaf_application_object) + zend_object_properties_size(ce));
+
+ memset(app, 0, XtOffsetOf(yaf_application_object, std));
+ app->std.handlers = &yaf_application_obj_handlers;
+ zend_object_std_init(&app->std, ce);
+
+ return &app->std;
+}
+/* }}} */
+
+static void yaf_application_free(zend_object *object) /* {{{ */ {
+ yaf_application_object *app = yaf_application_instance();
+
+ if ((app != php_yaf_application_fetch_object(object)) || !app->env) {
+ zend_object_std_dtor(object);
+ return;
+ }
+
+ zend_string_release(app->env);
+
+ OBJ_RELEASE(Z_OBJ(app->config));
+ OBJ_RELEASE(Z_OBJ(app->dispatcher));
+
+ zend_string_release(app->default_module);
+ zend_string_release(app->default_controller);
+ zend_string_release(app->default_action);
+ if (app->library) {
+ zend_string_release(app->library);
+ }
+ zend_string_release(app->directory);
+
+ if (app->ext) {
+ zend_string_release(app->ext);
+ }
+ if (app->bootstrap) {
+ zend_string_release(app->bootstrap);
+ }
+ if (app->view_ext) {
+ zend_string_release(app->view_ext);
+ }
+ if (app->base_uri) {
+ zend_string_release(app->base_uri);
+ }
+ if (app->err_msg) {
+ zend_string_release(app->err_msg);
+ }
+ if (app->modules) {
+ if (GC_DELREF(app->modules) == 0) {
+ GC_REMOVE_FROM_BUFFER(app->modules);
+ zend_array_destroy(app->modules);
+ }
+ }
+ if (app->properties) {
+ if (GC_DELREF(app->properties) == 0) {
+ GC_REMOVE_FROM_BUFFER(app->properties);
+ zend_array_destroy(app->properties);
+ }
+ }
+
+ zend_object_std_dtor(object);
+}
+/* }}} */
+
+static HashTable *yaf_application_get_gc(zval *object, zval **table, int *n) /* {{{ */ {
+ yaf_application_object *app = Z_YAFAPPOBJ_P(object);
+
+ *table = &app->dispatcher;
+ *n = 2;
+
+ return NULL;
+}
+/* }}} */
+
static HashTable *yaf_application_get_properties(zval *object) /* {{{ */ {
zval rv;
HashTable *ht;
@@ -599,70 +673,6 @@ static int yaf_application_parse_option(yaf_application_object *app) /* {{{ */ {
}
/* }}} */
-static zend_object* yaf_application_new(zend_class_entry *ce) /* {{{ */ {
- yaf_application_object *app = emalloc(sizeof(yaf_application_object) + zend_object_properties_size(ce));
-
- memset(app, 0, XtOffsetOf(yaf_application_object, std));
- app->std.handlers = &yaf_application_obj_handlers;
- zend_object_std_init(&app->std, ce);
-
- return &app->std;
-}
-/* }}} */
-
-static void yaf_application_free(zend_object *object) /* {{{ */ {
- yaf_application_object *app = yaf_application_instance();
-
- if ((app != php_yaf_application_fetch_object(object)) || !app->env) {
- zend_object_std_dtor(object);
- return;
- }
-
- zend_string_release(app->env);
-
- OBJ_RELEASE(Z_OBJ(app->config));
- OBJ_RELEASE(Z_OBJ(app->dispatcher));
-
- zend_string_release(app->default_module);
- zend_string_release(app->default_controller);
- zend_string_release(app->default_action);
- if (app->library) {
- zend_string_release(app->library);
- }
- zend_string_release(app->directory);
-
- if (app->ext) {
- zend_string_release(app->ext);
- }
- if (app->bootstrap) {
- zend_string_release(app->bootstrap);
- }
- if (app->view_ext) {
- zend_string_release(app->view_ext);
- }
- if (app->base_uri) {
- zend_string_release(app->base_uri);
- }
- if (app->err_msg) {
- zend_string_release(app->err_msg);
- }
- if (app->modules) {
- if (GC_DELREF(app->modules) == 0) {
- GC_REMOVE_FROM_BUFFER(app->modules);
- zend_array_destroy(app->modules);
- }
- }
- if (app->properties) {
- if (GC_DELREF(app->properties) == 0) {
- GC_REMOVE_FROM_BUFFER(app->properties);
- zend_array_destroy(app->properties);
- }
- }
-
- zend_object_std_dtor(object);
-}
-/* }}} */
-
/** {{{ proto Yaf_Application::__construct(mixed $config, string $environ = YAF_G(environ_name))
*/
PHP_METHOD(yaf_application, __construct) {
@@ -990,6 +1000,7 @@ zend_function_entry yaf_application_methods[] = {
PHP_ME(yaf_application, getLastErrorNo, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, getLastErrorMsg, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(yaf_application, clearLastError, yaf_application_void_arginfo, ZEND_ACC_PUBLIC)
+ PHP_MALIAS(yaf_application, getInstance, app, yaf_application_app_arginfo, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* }}} */
@@ -1009,7 +1020,7 @@ YAF_STARTUP_FUNCTION(application) {
memcpy(&yaf_application_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
yaf_application_obj_handlers.offset = XtOffsetOf(yaf_application_object, std);
yaf_application_obj_handlers.clone_obj = NULL;
- yaf_application_obj_handlers.get_gc = NULL;
+ yaf_application_obj_handlers.get_gc = yaf_application_get_gc;
yaf_application_obj_handlers.free_obj = yaf_application_free;
yaf_application_obj_handlers.get_properties = yaf_application_get_properties;
yaf_application_obj_handlers.read_property = yaf_application_read_property;
diff --git a/yaf_config.c b/yaf_config.c
index 4685e44b..a1739222 100644
--- a/yaf_config.c
+++ b/yaf_config.c
@@ -61,6 +61,16 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_config_isset_arginfo, 0, 0, 1)
ZEND_END_ARG_INFO()
/* }}} */
+static HashTable *yaf_config_get_gc(zval *object, zval **table, int *n) /* {{{ */ {
+ yaf_config_object *conf = Z_YAFCONFIGOBJ_P(object);;
+
+ *table = NULL;
+ *n = 0;
+
+ return conf->config;
+}
+/* }}} */
+
static HashTable *yaf_config_get_properties(zval *object) /* {{{ */ {
zval rv;
HashTable *ht;
@@ -412,7 +422,7 @@ YAF_STARTUP_FUNCTION(config) {
yaf_config_obj_handlers.offset = XtOffsetOf(yaf_config_object, std);
yaf_config_obj_handlers.free_obj = yaf_config_object_free;
yaf_config_obj_handlers.clone_obj = NULL;
- yaf_config_obj_handlers.get_gc = NULL;
+ yaf_config_obj_handlers.get_gc = yaf_config_get_gc;
yaf_config_obj_handlers.get_properties = yaf_config_get_properties;
#if defined(HAVE_SPL) && PHP_VERSION_ID < 70200
diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c
index 1d19c22d..86c712b9 100644
--- a/yaf_dispatcher.c
+++ b/yaf_dispatcher.c
@@ -105,33 +105,23 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_dispatcher_setaction_arginfo, 0, 0, 1)
ZEND_END_ARG_INFO()
/* }}} */
-static void yaf_dispatcher_obj_free(zend_object *object) /* {{{ */ {
- yaf_dispatcher_object *dispatcher = (yaf_dispatcher_object*)object;
-
- zval_ptr_dtor(&dispatcher->request);
- zval_ptr_dtor(&dispatcher->response);
- zval_ptr_dtor(&dispatcher->router);
- zval_ptr_dtor(&dispatcher->view);
- zend_hash_destroy(&dispatcher->plugins);
-
- zend_object_std_dtor(object);
-}
-/* }}} */
-
void yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr) /* {{{ */ {
yaf_application_object *app = Z_YAFAPPOBJ(YAF_G(app));
yaf_dispatcher_object *dispatcher;
if (IS_OBJECT != Z_TYPE(app->dispatcher)) {
- dispatcher = emalloc(sizeof(yaf_dispatcher_object));
+ dispatcher = emalloc(sizeof(yaf_dispatcher_object) + zend_object_properties_size(yaf_dispatcher_ce));
zend_object_std_init(&dispatcher->std, yaf_dispatcher_ce);
dispatcher->std.handlers = &yaf_dispatcher_obj_handlers;
- zend_hash_init(&dispatcher->plugins, 8, NULL, ZVAL_PTR_DTOR, 0);
- memset(&dispatcher->request, 0, sizeof(yaf_dispatcher_object) - sizeof(zend_object) - sizeof(zend_array));
-
yaf_router_instance(&dispatcher->router);
- dispatcher->auto_render = 1;
+
+ ZVAL_NULL(&dispatcher->request);
+ ZVAL_NULL(&dispatcher->response);
+ ZVAL_NULL(&dispatcher->view);
+ dispatcher->flags = YAF_DISPATCHER_AUTO_RENDER;
+ dispatcher->plugins = NULL;
+ dispatcher->properties = NULL;
ZVAL_OBJ(&app->dispatcher, &dispatcher->std);
return;
@@ -141,6 +131,87 @@ void yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr) /* {{{ */ {
}
/* }}} */
+static void yaf_dispatcher_obj_free(zend_object *object) /* {{{ */ {
+ yaf_dispatcher_object *dispatcher = php_yaf_dispatcher_fetch_object(object);
+
+ zval_ptr_dtor(&dispatcher->request);
+ zval_ptr_dtor(&dispatcher->response);
+ zval_ptr_dtor(&dispatcher->router);
+ zval_ptr_dtor(&dispatcher->view);
+
+ if (dispatcher->plugins) {
+ if (GC_DELREF(dispatcher->plugins) == 0) {
+ GC_REMOVE_FROM_BUFFER(dispatcher->plugins);
+ zend_array_destroy(dispatcher->plugins);
+ }
+ }
+
+ if (dispatcher->properties) {
+ if (GC_DELREF(dispatcher->properties) == 0) {
+ GC_REMOVE_FROM_BUFFER(dispatcher->properties);
+ zend_array_destroy(dispatcher->properties);
+ }
+ }
+
+ zend_object_std_dtor(object);
+}
+/* }}} */
+
+static HashTable *yaf_dispatcher_get_properties(zval *object) /* {{{ */ {
+ zval rv;
+ HashTable *ht;
+ yaf_dispatcher_object *dispatcher = Z_YAFDISPATCHEROBJ_P(object);
+
+ if (!dispatcher->properties) {
+ ALLOC_HASHTABLE(dispatcher->properties);
+ zend_hash_init(dispatcher->properties, 16, NULL, ZVAL_PTR_DTOR, 0);
+ HT_ALLOW_COW_VIOLATION(dispatcher->properties);
+ }
+
+ ht = dispatcher->properties;
+
+ ZVAL_BOOL(&rv, dispatcher->flags & YAF_DISPATCHER_AUTO_RENDER);
+ zend_hash_str_update(ht, "auto_render:protected", sizeof("auto_render:protected") - 1, &rv);
+ ZVAL_BOOL(&rv, dispatcher->flags & YAF_DISPATCHER_INSTANT_FLUSH);
+ zend_hash_str_update(ht, "instant_flush:protected", sizeof("instant_flush:protected") - 1, &rv);
+ ZVAL_BOOL(&rv, dispatcher->flags & YAF_DISPATCHER_RETURN_RESPONSE);
+ zend_hash_str_update(ht, "return_response:protected", sizeof("return_response:protected") - 1, &rv);
+
+ ZVAL_COPY(&rv, &dispatcher->request);
+ zend_hash_str_update(ht, "request:protected", sizeof("request:protected") - 1, &rv);
+ ZVAL_COPY(&rv, &dispatcher->response);
+ zend_hash_str_update(ht, "response:protected", sizeof("response:protected") - 1, &rv);
+ ZVAL_COPY(&rv, &dispatcher->router);
+ zend_hash_str_update(ht, "router:protected", sizeof("router:protected") - 1, &rv);
+ ZVAL_COPY(&rv, &dispatcher->view);
+ zend_hash_str_update(ht, "view:protected", sizeof("view:protected") - 1, &rv);
+
+ if (dispatcher->plugins) {
+ ZVAL_ARR(&rv, dispatcher->plugins);
+ GC_ADDREF(dispatcher->plugins);
+ } else {
+#if PHP_VERSION_ID < 70400
+ array_init(&rv);
+#else
+ ZVAL_EMPTY_ARRAY(&rv);
+#endif
+ }
+ zend_hash_str_update(ht, "plugins:protected", sizeof("plugins:protected") - 1, &rv);
+
+ return ht;
+}
+/* }}} */
+
+static HashTable *yaf_dispatcher_get_gc(zval *object, zval **table, int *n) /* {{{ */ {
+ yaf_dispatcher_object *dispatcher = Z_YAFDISPATCHEROBJ_P(object);
+
+ *table = &dispatcher->request;
+ *n = 4;
+
+ return dispatcher->plugins;
+}
+/* }}} */
+
static void yaf_dispatcher_get_call_parameters(yaf_request_object *request, zend_function *fptr, zval **params, unsigned *count) /* {{{ */ {
zval *arg;
unsigned current;
@@ -555,10 +626,11 @@ int yaf_dispatcher_handle(yaf_dispatcher_object *dispatcher) /* {{{ */ {
return 0;
}
- if (yaf_controller_auto_render(ctl, dispatcher->auto_render)) {
+ if (yaf_controller_auto_render(ctl, dispatcher->flags & YAF_DISPATCHER_AUTO_RENDER)) {
zval res;
- if ((yaf_controller_render(&controller, origin_action, NULL, dispatcher->instantly_flush? NULL : &res))) {
- if (!dispatcher->instantly_flush) {
+ zend_bool flush_instantly = dispatcher->flags & YAF_DISPATCHER_INSTANT_FLUSH;
+ if ((yaf_controller_render(&controller, origin_action, NULL, flush_instantly? NULL : &res))) {
+ if (!flush_instantly) {
ZEND_ASSERT(Z_TYPE(res) == IS_STRING);
yaf_response_alter_body(Z_YAFRESPONSEOBJ(dispatcher->response), NULL, Z_STR(res), YAF_RESPONSE_APPEND );
zend_string_release(Z_STR(res));
@@ -724,7 +796,7 @@ yaf_response_t *yaf_dispatcher_dispatch(yaf_dispatcher_object *dispatcher) /* {{
return NULL;
}
- if (!dispatcher->return_response) {
+ if (!(dispatcher->flags & YAF_DISPATCHER_RETURN_RESPONSE)) {
yaf_response_response(&dispatcher->response);
yaf_response_clear_body(Z_YAFRESPONSEOBJ(dispatcher->response), NULL);
@@ -788,7 +860,7 @@ PHP_METHOD(yaf_dispatcher, disableView) {
return;
}
- dispatcher->auto_render = 0;
+ dispatcher->flags &= ~YAF_DISPATCHER_AUTO_RENDER;
RETURN_ZVAL(getThis(), 1, 0);
}
@@ -803,7 +875,7 @@ PHP_METHOD(yaf_dispatcher, enableView) {
return;
}
- dispatcher->auto_render = 1;
+ dispatcher->flags |= YAF_DISPATCHER_AUTO_RENDER;
RETURN_ZVAL(getThis(), 1, 0);
}
@@ -820,10 +892,14 @@ PHP_METHOD(yaf_dispatcher, returnResponse) {
}
if (ZEND_NUM_ARGS()) {
- dispatcher->return_response = return_response;
+ if (return_response) {
+ dispatcher->flags |= YAF_DISPATCHER_RETURN_RESPONSE;
+ } else {
+ dispatcher->flags &= ~YAF_DISPATCHER_RETURN_RESPONSE;
+ }
RETURN_ZVAL(getThis(), 1, 0);
} else {
- RETURN_BOOL(dispatcher->return_response);
+ RETURN_BOOL(dispatcher->flags & YAF_DISPATCHER_RETURN_RESPONSE);
}
}
/* }}} */
@@ -839,10 +915,15 @@ PHP_METHOD(yaf_dispatcher, flushInstantly) {
}
if (ZEND_NUM_ARGS()) {
- dispatcher->instantly_flush = instantly_flush? 1 : 0;
+ if (instantly_flush) {
+ dispatcher->flags |= YAF_DISPATCHER_INSTANT_FLUSH;
+ } else {
+ dispatcher->flags &= ~YAF_DISPATCHER_INSTANT_FLUSH;
+ }
+
RETURN_ZVAL(getThis(), 1, 0);
} else {
- RETURN_BOOL(dispatcher->instantly_flush);
+ RETURN_BOOL(dispatcher->flags & YAF_DISPATCHER_INSTANT_FLUSH);
}
}
/* }}} */
@@ -864,8 +945,12 @@ PHP_METHOD(yaf_dispatcher, registerPlugin) {
}
+ if (!dispatcher->plugins) {
+ ALLOC_HASHTABLE(dispatcher->plugins);
+ zend_hash_init(dispatcher->plugins, 8, NULL, ZVAL_PTR_DTOR, 0);
+ }
Z_ADDREF_P(plugin);
- zend_hash_next_index_insert(&dispatcher->plugins, plugin);
+ zend_hash_next_index_insert(dispatcher->plugins, plugin);
RETURN_ZVAL(getThis(), 1, 0);
}
@@ -897,10 +982,6 @@ PHP_METHOD(yaf_dispatcher, getInstance) {
return;
}
- if (!yaf_application_instance()) {
- RETURN_NULL();
- }
-
yaf_dispatcher_instance(return_value);
}
/* }}} */
@@ -1003,10 +1084,15 @@ PHP_METHOD(yaf_dispatcher, autoRender) {
}
if (ZEND_NUM_ARGS()) {
- dispatcher->auto_render = flag? 1 : 0;
+ if (flag) {
+ dispatcher->flags |= YAF_DISPATCHER_AUTO_RENDER;
+ } else {
+ dispatcher->flags &= ~YAF_DISPATCHER_AUTO_RENDER;
+ }
+
RETURN_ZVAL(getThis(), 1, 0);
} else {
- RETURN_BOOL(dispatcher->auto_render);
+ RETURN_BOOL(dispatcher->flags & YAF_DISPATCHER_AUTO_RENDER);
}
}
/* }}} */
@@ -1232,8 +1318,11 @@ YAF_STARTUP_FUNCTION(dispatcher) {
yaf_dispatcher_ce->unserialize = zend_class_unserialize_deny;
memcpy(&yaf_dispatcher_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- yaf_dispatcher_obj_handlers.clone_obj = NULL;
+ yaf_dispatcher_obj_handlers.offset = XtOffsetOf(yaf_dispatcher_object, std);
yaf_dispatcher_obj_handlers.free_obj = yaf_dispatcher_obj_free;
+ yaf_dispatcher_obj_handlers.clone_obj = NULL;
+ yaf_dispatcher_obj_handlers.get_gc = yaf_dispatcher_get_gc;
+ yaf_dispatcher_obj_handlers.get_properties = yaf_dispatcher_get_properties;
return SUCCESS;
}
diff --git a/yaf_dispatcher.h b/yaf_dispatcher.h
index 4b670192..82135073 100644
--- a/yaf_dispatcher.h
+++ b/yaf_dispatcher.h
@@ -28,13 +28,37 @@
#define YAF_PLUGIN_HOOK_LOOPSHUTDOWN "dispatchloopshutdown"
#define YAF_PLUGIN_HOOK_PRERESPONSE "preresponse"
+extern zend_class_entry *yaf_dispatcher_ce;
+
+#define YAF_DISPATCHER_AUTO_RENDER (1<<0)
+#define YAF_DISPATCHER_INSTANT_FLUSH (1<<1)
+#define YAF_DISPATCHER_RETURN_RESPONSE (1<<2)
+
+typedef struct {
+ zend_uchar flags;
+ yaf_request_t request;
+ yaf_response_t response;
+ yaf_router_t router;
+ yaf_view_t view;
+ zend_array *plugins;
+ zend_array *properties;
+ zend_object std;
+} yaf_dispatcher_object;
+
+#define Z_YAFDISPATCHEROBJ(zv) (php_yaf_dispatcher_fetch_object(Z_OBJ(zv)))
+#define Z_YAFDISPATCHEROBJ_P(zv) Z_YAFDISPATCHEROBJ(*zv)
+
+static zend_always_inline yaf_dispatcher_object *php_yaf_dispatcher_fetch_object(zend_object *obj) {
+ return (yaf_dispatcher_object *)((char*)(obj) - XtOffsetOf(yaf_dispatcher_object, std));
+}
+
#define YAF_PLUGIN_HANDLE(dispatcher, ev) \
do { \
yaf_dispatcher_object *_d = (dispatcher); \
- if (zend_hash_num_elements(&_d->plugins)) { \
+ if (_d->plugins) { \
zval _r, *_t;\
zend_function *_f; \
- ZEND_HASH_FOREACH_VAL(&_d->plugins, _t) { \
+ ZEND_HASH_FOREACH_VAL(_d->plugins, _t) { \
if ((_f = zend_hash_str_find_ptr(&(Z_OBJCE_P(_t)->function_table), (ev), sizeof(ev) - 1))) { \
yaf_call_user_method(Z_OBJ_P(_t), _f, &_r, 2, &_d->request, &_d->response); \
} \
@@ -42,22 +66,6 @@
} \
} while(0)
-extern zend_class_entry *yaf_dispatcher_ce;
-
-typedef struct {
- zend_object std;
- zend_array plugins;
- yaf_request_t request;
- yaf_response_t response;
- yaf_router_t router;
- yaf_view_t view;
- zend_bool auto_render;
- zend_bool instantly_flush;
- zend_bool return_response;
-} yaf_dispatcher_object;
-
-#define Z_YAFDISPATCHEROBJ(zv) ((yaf_dispatcher_object*)(Z_OBJ(zv)))
-#define Z_YAFDISPATCHEROBJ_P(zv) Z_YAFDISPATCHEROBJ(*zv)
void yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr);
yaf_response_t *yaf_dispatcher_dispatch(yaf_dispatcher_object *dispatcher);
diff --git a/yaf_request.c b/yaf_request.c
index d1f4a0f5..c0e5e738 100644
--- a/yaf_request.c
+++ b/yaf_request.c
@@ -149,6 +149,17 @@ static void yaf_request_object_free(zend_object *object) /* {{{ */ {
}
/* }}} */
+static HashTable *yaf_request_get_gc(zval *object, zval **table, int *n) /* {{{ */
+{
+ yaf_request_object *request = Z_YAFREQUESTOBJ_P(object);
+
+ *table = NULL;
+ *n = 0;
+
+ return request->params;
+}
+/* }}} */
+
static HashTable *yaf_request_get_properties(zval *object) /* {{{ */ {
zval rv;
HashTable *ht;
@@ -1241,8 +1252,8 @@ YAF_STARTUP_FUNCTION(request){
yaf_request_obj_handlers.get_properties = yaf_request_get_properties;;
yaf_request_obj_handlers.read_property = yaf_request_read_property;
yaf_request_obj_handlers.write_property = yaf_request_write_property;
+ yaf_request_obj_handlers.get_gc = yaf_request_get_gc;
yaf_request_obj_handlers.clone_obj = NULL;
- yaf_request_obj_handlers.get_gc = NULL;
YAF_STARTUP(request_http);
YAF_STARTUP(request_simple);