Skip to content

Commit

Permalink
Fix #1040 + tests
Browse files Browse the repository at this point in the history
Cherry picked from commits:
  * cda9f28
  * f270a96
  * d43feb2
  * 983857e
  • Loading branch information
sjinks committed Sep 18, 2013
1 parent 2181ac0 commit 73b6b7a
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 131 deletions.
6 changes: 6 additions & 0 deletions ext/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ PHP_METHOD(Phalcon_Dispatcher, dispatch){
if (!phalcon_memnstr_str(handler_name, SL("\\"))) {
PHALCON_INIT_NVAR(camelized_class);
phalcon_camelize(camelized_class, handler_name);
} else if (phalcon_start_with_str(handler_name, SL("\\"))) {
PHALCON_INIT_NVAR(camelized_class);
ZVAL_STRINGL(camelized_class, Z_STRVAL_P(handler_name)+1, Z_STRLEN_P(handler_name)-1, 1);
} else {
PHALCON_CPY_WRT(camelized_class, handler_name);
}
Expand Down Expand Up @@ -1108,6 +1111,9 @@ PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){
if (!phalcon_memnstr_str(handler_name, SL("\\"))) {
PHALCON_INIT_VAR(camelized_class);
phalcon_camelize(camelized_class, handler_name);
} else if (phalcon_start_with_str(handler_name, SL("\\"))) {
PHALCON_INIT_VAR(camelized_class);
ZVAL_STRINGL(camelized_class, Z_STRVAL_P(handler_name)+1, Z_STRLEN_P(handler_name)-1, 1);
} else {
PHALCON_CPY_WRT(camelized_class, handler_name);
}
Expand Down
19 changes: 15 additions & 4 deletions ext/mvc/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
zval *module_object = NULL, *modules, *exception_msg = NULL;
zval *module, *class_name = NULL, *path, *module_params;
zval *implicit_view, *view, *namespace_name;
zval *controller_name = NULL, *action_name = NULL, *params = NULL;
zval *controller_name = NULL, *action_name = NULL, *params = NULL, *exact;
zval *dispatcher, *controller, *returned_response = NULL;
zval *possible_response, *render_status = NULL, *response = NULL;
zval *content;
zval *content, *real_controller_name;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -405,7 +405,7 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
if (phalcon_is_instance_of(module, SL("Closure") TSRMLS_CC)) {
PHALCON_INIT_VAR(module_params);
array_init_size(module_params, 1);
phalcon_array_append(&module_params, dependency_injector, PH_SEPARATE);
phalcon_array_append(&module_params, dependency_injector, 0);

PHALCON_INIT_NVAR(status);
PHALCON_CALL_USER_FUNC_ARRAY(status, module, module_params);
Expand Down Expand Up @@ -463,6 +463,17 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
PHALCON_INIT_VAR(params);
phalcon_call_method(params, router, "getparams");

PHALCON_INIT_VAR(exact);
phalcon_call_method(exact, router, "isexactcontrollername");

if (zend_is_true(exact)) {
PHALCON_INIT_VAR(real_controller_name);
PHALCON_CONCAT_SV(real_controller_name, "\\", controller_name);
}
else {
real_controller_name = controller_name;
}

PHALCON_INIT_NVAR(service);
ZVAL_STRING(service, "dispatcher", 1);

Expand All @@ -474,7 +485,7 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
*/
phalcon_call_method_p1_noret(dispatcher, "setmodulename", module_name);
phalcon_call_method_p1_noret(dispatcher, "setnamespacename", namespace_name);
phalcon_call_method_p1_noret(dispatcher, "setcontrollername", controller_name);
phalcon_call_method_p1_noret(dispatcher, "setcontrollername", real_controller_name);
phalcon_call_method_p1_noret(dispatcher, "setactionname", action_name);
phalcon_call_method_p1_noret(dispatcher, "setparams", params);

Expand Down
88 changes: 53 additions & 35 deletions ext/mvc/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Router){
zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultParams"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_mvc_router_ce, SL("_removeExtraSlashes"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_mvc_router_ce, SL("_notFoundPaths"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_mvc_router_ce, SL("_isExactControllerName"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);

zend_declare_class_constant_long(phalcon_mvc_router_ce, SL("URI_SOURCE_GET_URL"), 0 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_mvc_router_ce, SL("URI_SOURCE_SERVER_REQUEST_URI"), 1 TSRMLS_CC);
Expand Down Expand Up @@ -456,6 +457,7 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){
HashTable *ah0, *ah1;
HashPosition hp0, hp1;
zval **hd;
zval *exact = NULL;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -691,52 +693,49 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){

PHALCON_GET_HKEY(part, ah1, hp1);
PHALCON_GET_HVALUE(position);

if (phalcon_array_isset(matches, position)) {

PHALCON_OBS_NVAR(match_position);
phalcon_array_fetch(&match_position, matches, position, PH_NOISY);

/**
* Check if the part has a converter
*/
if (Z_TYPE_P(converters) == IS_ARRAY) {

if (Z_TYPE_P(part) != IS_STRING || Z_STRVAL_P(part)[0] != '\0') {
if (phalcon_array_isset(matches, position)) {
PHALCON_OBS_NVAR(match_position);
phalcon_array_fetch(&match_position, matches, position, PH_NOISY);

/**
* Check if the part has a converter
*/
if (phalcon_array_isset(converters, part)) {
PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 1);
phalcon_array_append(&parameters, match_position, PH_SEPARATE);

PHALCON_OBS_NVAR(converter);
phalcon_array_fetch(&converter, converters, part, PH_NOISY);


PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 1);
phalcon_array_append(&parameters, match_position, 0);

PHALCON_INIT_NVAR(converted_part);
PHALCON_CALL_USER_FUNC_ARRAY(converted_part, converter, parameters);
phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY | PH_SEPARATE);
phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY);
zend_hash_move_forward_ex(ah1, &hp1);
continue;
}
}

/**
* Update the parts if there is no converter
*/
phalcon_array_update_zval(&parts, part, &match_position, PH_COPY | PH_SEPARATE);
} else {
/**
* Apply the converters anyway
*/
if (Z_TYPE_P(converters) == IS_ARRAY) {

/**
* Update the parts if there is no converter
*/
phalcon_array_update_zval(&parts, part, &match_position, PH_COPY);
} else {
/**
* Apply the converters anyway
*/
if (phalcon_array_isset(converters, part)) {
PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 1);
phalcon_array_append(&parameters, position, PH_SEPARATE);

PHALCON_OBS_NVAR(converter);
phalcon_array_fetch(&converter, converters, part, PH_NOISY);


PHALCON_INIT_NVAR(parameters);
array_init_size(parameters, 1);
phalcon_array_append(&parameters, position, 0);

PHALCON_INIT_NVAR(converted_part);
PHALCON_CALL_USER_FUNC_ARRAY(converted_part, converter, parameters);
phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY | PH_SEPARATE);
phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY);
}
}
}
Expand Down Expand Up @@ -818,8 +817,20 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){
phalcon_read_property_this(&default_module, this_ptr, SL("_defaultModule"), PH_NOISY_CC);
phalcon_update_property_this(this_ptr, SL("_module"), default_module TSRMLS_CC);
}

/**

if (phalcon_array_isset_string(parts, SS("\0exact"))) {
PHALCON_OBS_VAR(exact);
phalcon_array_fetch_string(&exact, parts, SL("\0exact"), PH_NOISY);
phalcon_update_property_this(this_ptr, SL("_isExactControllerName"), exact TSRMLS_CC);
phalcon_array_unset_string(&parts, SS("\0exact"), PH_SEPARATE);
}
else {
PHALCON_INIT_VAR(exact);
ZVAL_FALSE(exact);
phalcon_update_property_this(this_ptr, SL("_isExactControllerName"), exact TSRMLS_CC);
}

/**
* Check for a controller
*/
if (phalcon_array_isset_string(parts, SS("controller"))) {
Expand Down Expand Up @@ -1423,3 +1434,10 @@ PHP_METHOD(Phalcon_Mvc_Router, getRouteByName){
RETURN_MM_FALSE;
}

/**
* Returns whether controller name should not be mangled
*/
PHP_METHOD(Phalcon_Mvc_Router, isExactControllerName) {
RETURN_MEMBER(this_ptr, "_isExactControllerName");
}

5 changes: 3 additions & 2 deletions ext/mvc/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ PHP_METHOD(Phalcon_Mvc_Router, wasMatched);
PHP_METHOD(Phalcon_Mvc_Router, getRoutes);
PHP_METHOD(Phalcon_Mvc_Router, getRouteById);
PHP_METHOD(Phalcon_Mvc_Router, getRouteByName);
PHP_METHOD(Phalcon_Mvc_Router, isExactControllerName);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_router___construct, 0, 0, 0)
ZEND_ARG_INFO(0, defaultRoutes)
Expand Down Expand Up @@ -187,7 +188,7 @@ PHALCON_INIT_FUNCS(phalcon_mvc_router_method_entry){
PHP_ME(Phalcon_Mvc_Router, wasMatched, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Router, getRoutes, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Router, getRouteById, arginfo_phalcon_mvc_router_getroutebyid, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Router, getRouteByName, arginfo_phalcon_mvc_router_getroutebyname, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Router, getRouteByName, arginfo_phalcon_mvc_router_getroutebyname, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Router, isExactControllerName, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};

Loading

0 comments on commit 73b6b7a

Please sign in to comment.