Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Jul 5, 2016
1 parent 253e87b commit bcb4eba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
25 changes: 16 additions & 9 deletions yaf_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ void yaf_dispatcher_exception_handler(yaf_dispatcher_t *dispatcher, yaf_request_
yaf_request_set_dispatched(request, 0);

view = yaf_dispatcher_init_view(dispatcher, NULL, NULL, &rv);

if (UNEXPECTED(!view)) {
return;
}
Expand Down Expand Up @@ -812,15 +813,19 @@ int yaf_dispatcher_route(yaf_dispatcher_t *dispatcher, yaf_request_t *request) /
dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_ROUTER), 1, NULL);
if (EXPECTED(IS_OBJECT == Z_TYPE_P(router))) {
if (EXPECTED((router_ce = Z_OBJCE_P(router)) == yaf_router_ce)) {
/* use built-in router */
yaf_router_route(router, request);
/* use built-in route */
if (yaf_router_route(router, request)) {
return 1;
}
} else {
/* user custom router */
/* user custom route */
zend_call_method_with_1_params(router, router_ce, NULL, "route", &ret, request);
if (Z_TYPE(ret) != IS_TRUE) {
yaf_trigger_error(YAF_ERR_ROUTE_FAILED, "Routing request faild");
zval_ptr_dtor(&ret);
return 0;
}
zval_ptr_dtor(&ret);
}
return 1;
}
Expand Down Expand Up @@ -900,8 +905,9 @@ yaf_response_t *yaf_dispatcher_dispatch(yaf_dispatcher_t *dispatcher, zval *resp

if (Z_TYPE_P(return_response) == IS_FALSE) {
zval ret;
/* it must return bool */
zend_call_method_with_0_params(response, Z_OBJCE_P(response), NULL, "response", &ret);
/* it must return bool */
/* zval_ptr_dtor(&ret); */
yaf_response_clear_body(response, NULL);
}

Expand Down Expand Up @@ -996,7 +1002,7 @@ PHP_METHOD(yaf_dispatcher, returnResponse) {

if (ZEND_NUM_ARGS()) {
zend_update_property_bool(yaf_dispatcher_ce,
self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_RETURN), (auto_response)? 1:0);
self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_RETURN), auto_response);
RETURN_ZVAL(self, 1, 0);
} else {
RETURN_BOOL(Z_TYPE_P(zend_read_property(yaf_dispatcher_ce,
Expand All @@ -1017,7 +1023,7 @@ PHP_METHOD(yaf_dispatcher, flushInstantly) {

if (ZEND_NUM_ARGS()) {
zend_update_property_bool(yaf_dispatcher_ce,
self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_FLUSH), (instantly_flush)? 1:0);
self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_FLUSH), instantly_flush);
RETURN_ZVAL(self, 1, 0);
} else {
RETURN_BOOL(Z_TYPE_P(zend_read_property(yaf_dispatcher_ce,
Expand All @@ -1036,7 +1042,8 @@ PHP_METHOD(yaf_dispatcher, registerPlugin) {
return;
}

if (EXPECTED(Z_TYPE_P(plugin) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(plugin), yaf_plugin_ce))) {
if (EXPECTED(Z_TYPE_P(plugin) != IS_OBJECT ||
!instanceof_function(Z_OBJCE_P(plugin), yaf_plugin_ce))) {
php_error_docref(NULL, E_WARNING, "Expect a %s instance", ZSTR_VAL(yaf_plugin_ce->name));
RETURN_FALSE;
}
Expand All @@ -1060,8 +1067,8 @@ PHP_METHOD(yaf_dispatcher, setRequest) {
return;
}

if (IS_OBJECT != Z_TYPE_P(request)
|| !instanceof_function(Z_OBJCE_P(request), yaf_request_ce)) {
if (IS_OBJECT != Z_TYPE_P(request) ||
!instanceof_function(Z_OBJCE_P(request), yaf_request_ce)) {
php_error_docref(NULL, E_WARNING, "Expects a %s instance", ZSTR_VAL(yaf_request_ce->name));
RETURN_FALSE;
}
Expand Down
6 changes: 3 additions & 3 deletions yaf_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ yaf_registry_t *yaf_registry_instance(yaf_registry_t *this_ptr) /* {{{ */ {
yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_INSTANCE), 1);

if (UNEXPECTED(Z_TYPE_P(instance) != IS_OBJECT ||
!instanceof_function(Z_OBJCE_P(instance), yaf_registry_ce))) {
!instanceof_function(Z_OBJCE_P(instance), yaf_registry_ce))) {
zval regs;

object_init_ex(this_ptr, yaf_registry_ce);
Expand Down Expand Up @@ -176,8 +176,8 @@ PHP_METHOD(yaf_registry, has) {
/** {{{ proto public Yaf_Registry::getInstance(void)
*/
PHP_METHOD(yaf_registry, getInstance) {
yaf_registry_t *registry, rregistry;
registry = yaf_registry_instance(&rregistry);
yaf_registry_t *registry, rv = {0};
registry = yaf_registry_instance(&rv);
RETURN_ZVAL(registry, 1, 0);
}
/* }}} */
Expand Down
9 changes: 5 additions & 4 deletions yaf_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ yaf_router_t * yaf_router_instance(yaf_router_t *this_ptr) {
/** {{{ int yaf_router_route(yaf_router_t *router, yaf_request_t *request)
*/
int yaf_router_route(yaf_router_t *router, yaf_request_t *request) {
zval *routers, ret;
zval *routers, ret;
yaf_route_t *route;
HashTable *ht;
zend_string *key;
ulong idx = 0;
zend_long idx;

routers = zend_read_property(yaf_router_ce, router, ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_ROUTES), 1, NULL);

Expand All @@ -94,13 +94,14 @@ int yaf_router_route(yaf_router_t *router, yaf_request_t *request) {
router, ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_CURRENT_ROUTE), idx);
}
yaf_request_set_routed(request, 1);
break;
return 1;
} else {
zval_ptr_dtor(&ret);
continue;
}
} ZEND_HASH_FOREACH_END();
return 1;

return 0;
}
/* }}} */

Expand Down

0 comments on commit bcb4eba

Please sign in to comment.