From 73b6b7a93250c0d7752aa8f7502ff09760ab3837 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sat, 24 Aug 2013 09:21:46 +0300 Subject: [PATCH] Fix #1040 + tests Cherry picked from commits: * cda9f28e76521eed618300f5cdf6399a09b00b8e * f270a9673c4f64d2ecf5ae8aa31a66269180b643 * d43feb268b65dbae5067ffc208b63b9750489c5a * 983857ede086e70c1597fdf021cf1643d769a18c --- ext/dispatcher.c | 6 ++ ext/mvc/application.c | 19 ++++- ext/mvc/router.c | 88 +++++++++++++--------- ext/mvc/router.h | 5 +- ext/mvc/router/annotations.c | 97 +++++++++---------------- ext/mvc/router/route.c | 39 +++++----- ext/mvc/routerinterface.c | 6 ++ ext/mvc/routerinterface.h | 1 + unit-tests/RouterMvcAnnotationsTest.php | 15 ++-- 9 files changed, 145 insertions(+), 131 deletions(-) diff --git a/ext/dispatcher.c b/ext/dispatcher.c index fa1fdafab28..06bf7369a92 100644 --- a/ext/dispatcher.c +++ b/ext/dispatcher.c @@ -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); } @@ -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); } diff --git a/ext/mvc/application.c b/ext/mvc/application.c index f305e250fd3..eae1868f18f 100644 --- a/ext/mvc/application.c +++ b/ext/mvc/application.c @@ -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(); @@ -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); @@ -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); @@ -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); diff --git a/ext/mvc/router.c b/ext/mvc/router.c index 667bd7e6479..06a3b394cab 100644 --- a/ext/mvc/router.c +++ b/ext/mvc/router.c @@ -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); @@ -456,6 +457,7 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){ HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; + zval *exact = NULL; PHALCON_MM_GROW(); @@ -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(¶meters, 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(¶meters, 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(¶meters, 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(¶meters, 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); } } } @@ -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"))) { @@ -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"); +} + diff --git a/ext/mvc/router.h b/ext/mvc/router.h index 14824cc02bd..39ab224f5a0 100644 --- a/ext/mvc/router.h +++ b/ext/mvc/router.h @@ -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) @@ -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 }; - diff --git a/ext/mvc/router/annotations.c b/ext/mvc/router/annotations.c index f555cda6b07..74de4403bfd 100644 --- a/ext/mvc/router/annotations.c +++ b/ext/mvc/router/annotations.c @@ -164,11 +164,11 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ zval *uri = NULL, *real_uri = NULL, *processed, *annotations_service = NULL; zval *handlers, *controller_suffix, *scope = NULL, *prefix = NULL; zval *dependency_injector = NULL, *service = NULL, *handler = NULL; - zval *controller_name = NULL, *lower_controller_name = NULL; - zval *namespace_name = NULL, *module_name = NULL, *sufixed = NULL; + zval *controller_name = NULL; + zval *namespace_name = NULL, *module_name = NULL, *suffixed = NULL; zval *handler_annotations = NULL, *class_annotations = NULL; zval *annotations = NULL, *annotation = NULL, *method_annotations = NULL; - zval *lowercased = NULL, *collection = NULL, *method = NULL; + zval *collection = NULL, *method = NULL; HashTable *ah0, *ah1, *ah2, *ah3; HashPosition hp0, hp1, hp2, hp3; zval **hd; @@ -252,12 +252,6 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ PHALCON_INIT_NVAR(controller_name); phalcon_get_class_ns(controller_name, handler, 0 TSRMLS_CC); - /** - * The lowercased class name is used as controller - */ - PHALCON_INIT_NVAR(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); - /** * Extract the namespace from the namespaced class */ @@ -266,9 +260,6 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ } else { PHALCON_CPY_WRT(controller_name, handler); - PHALCON_INIT_NVAR(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); - PHALCON_INIT_NVAR(namespace_name); } @@ -284,14 +275,14 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ PHALCON_INIT_NVAR(module_name); } - PHALCON_INIT_NVAR(sufixed); - PHALCON_CONCAT_VV(sufixed, handler, controller_suffix); + PHALCON_INIT_NVAR(suffixed); + PHALCON_CONCAT_VV(suffixed, handler, controller_suffix); /** * Get the annotations from the class */ PHALCON_INIT_NVAR(handler_annotations); - phalcon_call_method_p1(handler_annotations, annotations_service, "get", sufixed); + phalcon_call_method_p1(handler_annotations, annotations_service, "get", suffixed); /** * Process class annotations @@ -328,9 +319,6 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ phalcon_call_method(method_annotations, handler_annotations, "getmethodsannotations"); if (Z_TYPE_P(method_annotations) == IS_ARRAY) { - PHALCON_INIT_NVAR(lowercased); - phalcon_uncamelize(lowercased, handler); - phalcon_is_iterable(method_annotations, &ah2, &hp2, 0, 0); while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { @@ -349,7 +337,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ PHALCON_GET_HVALUE(annotation); - phalcon_call_method_p5_noret(this_ptr, "processactionannotation", module_name, namespace_name, lower_controller_name, method, annotation); + phalcon_call_method_p5_noret(this_ptr, "processactionannotation", module_name, namespace_name, controller_name, method, annotation); zend_hash_move_forward_ex(ah3, &hp3); } @@ -422,22 +410,21 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processControllerAnnotation){ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ zval *module, *namespace, *controller, *action; - zval *annotation, *is_route = NULL, *methods = NULL, *name, *action_suffix; + zval *annotation, *methods = NULL, *name; zval *empty_str, *real_action_name, *action_name; - zval *route_prefix, *parameter = NULL, *paths = NULL, *position; + zval *parameter = NULL, *paths = NULL, *position; zval *value, *uri = NULL, *route, *converts = NULL, *convert = NULL, *param = NULL; - zval *conversor_param = NULL, *route_name; + zval *conversor_param = NULL, *route_name, *z_true; + zval *action_suffix, *route_prefix; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; + int is_route = 1; PHALCON_MM_GROW(); phalcon_fetch_params(1, 5, 0, &module, &namespace, &controller, &action, &annotation); - PHALCON_INIT_VAR(is_route); - ZVAL_BOOL(is_route, 0); - PHALCON_INIT_VAR(methods); PHALCON_INIT_VAR(name); @@ -447,47 +434,30 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ * Find if the route is for adding routes */ if (PHALCON_IS_STRING(name, "Route")) { - ZVAL_BOOL(is_route, 1); - } else { - if (PHALCON_IS_STRING(name, "Get")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - ZVAL_STRING(methods, "GET", 1); - } else { - if (PHALCON_IS_STRING(name, "Post")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "POST", 1); - } else { - if (PHALCON_IS_STRING(name, "Put")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "PUT", 1); - } else { - if (PHALCON_IS_STRING(name, "Options")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "OPTIONS", 1); - } - } - } - } + is_route = 1; + } else if (PHALCON_IS_STRING(name, "Get")) { + is_route = 1; + ZVAL_STRING(methods, "GET", 1); + } else if (PHALCON_IS_STRING(name, "Post")) { + is_route = 1; + ZVAL_STRING(methods, "POST", 1); + } else if (PHALCON_IS_STRING(name, "Put")) { + is_route = 1; + ZVAL_STRING(methods, "PUT", 1); + } else if (PHALCON_IS_STRING(name, "Options")) { + is_route = 1; + ZVAL_STRING(methods, "OPTIONS", 1); } - if (PHALCON_IS_TRUE(is_route)) { - + if (is_route) { PHALCON_OBS_VAR(action_suffix); phalcon_read_property_this(&action_suffix, this_ptr, SL("_actionSuffix"), PH_NOISY_CC); + + PHALCON_OBS_VAR(route_prefix); + phalcon_read_property_this(&route_prefix, this_ptr, SL("_routePrefix"), PH_NOISY_CC); PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); + ZVAL_EMPTY_STRING(empty_str); PHALCON_INIT_VAR(real_action_name); phalcon_fast_str_replace(real_action_name, action_suffix, empty_str, action); @@ -495,9 +465,6 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ PHALCON_INIT_VAR(action_name); phalcon_fast_strtolower(action_name, real_action_name); - PHALCON_OBS_VAR(route_prefix); - phalcon_read_property_this(&route_prefix, this_ptr, SL("_routePrefix"), PH_NOISY_CC); - PHALCON_INIT_VAR(parameter); ZVAL_STRING(parameter, "paths", 1); @@ -524,9 +491,13 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ if (Z_TYPE_P(namespace) == IS_STRING) { phalcon_array_update_string(&paths, SL("namespace"), &namespace, PH_COPY | PH_SEPARATE); } + + PHALCON_INIT_VAR(z_true); + ZVAL_TRUE(z_true); phalcon_array_update_string(&paths, SL("controller"), &controller, PH_COPY | PH_SEPARATE); phalcon_array_update_string(&paths, SL("action"), &action_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_string(&paths, SL("\0exact"), &z_true, PH_COPY); PHALCON_INIT_VAR(position); ZVAL_LONG(position, 0); diff --git a/ext/mvc/router/route.c b/ext/mvc/router/route.c index 75a2fb224d4..eddbeb1d8e7 100644 --- a/ext/mvc/router/route.c +++ b/ext/mvc/router/route.c @@ -141,7 +141,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){ zval *pattern, *compiled_pattern = NULL, *id_pattern; - zval *wildcard = NULL, *pattern_copy = NULL, *params_pattern; + zval wildcard, *pattern_copy = NULL, *params_pattern; zval *int_pattern; PHALCON_MM_GROW(); @@ -165,78 +165,78 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){ * Replace the module part */ if (phalcon_memnstr_str(pattern, SL("/:module"))) { - PHALCON_INIT_VAR(wildcard); - ZVAL_STRING(wildcard, "/:module", 1); + INIT_ZVAL(wildcard); + ZVAL_STRING(&wildcard, "/:module", 0); PHALCON_CPY_WRT(pattern_copy, compiled_pattern); PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy); } /** * Replace the controller placeholder */ if (phalcon_memnstr_str(pattern, SL("/:controller"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:controller", 1); + INIT_ZVAL(wildcard); + ZVAL_STRING(&wildcard, "/:controller", 0); PHALCON_CPY_WRT(pattern_copy, compiled_pattern); PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy); } /** * Replace the namespace placeholder */ if (phalcon_memnstr_str(pattern, SL("/:namespace"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:namespace", 1); + INIT_ZVAL(wildcard) + ZVAL_STRING(&wildcard, "/:namespace", 0); PHALCON_CPY_WRT(pattern_copy, compiled_pattern); PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy); } /** * Replace the action placeholder */ if (phalcon_memnstr_str(pattern, SL("/:action"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:action", 1); + INIT_ZVAL(wildcard); + ZVAL_STRING(&wildcard, "/:action", 0); PHALCON_CPY_WRT(pattern_copy, compiled_pattern); PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy); } /** * Replace the params placeholder */ if (phalcon_memnstr_str(pattern, SL("/:params"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:params", 1); + INIT_ZVAL(wildcard); + ZVAL_STRING(&wildcard, "/:params", 0); PHALCON_INIT_VAR(params_pattern); ZVAL_STRING(params_pattern, "(/.*)*", 1); PHALCON_CPY_WRT(pattern_copy, compiled_pattern); PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, params_pattern, pattern_copy); + phalcon_fast_str_replace(compiled_pattern, &wildcard, params_pattern, pattern_copy); } /** * Replace the int placeholder */ if (phalcon_memnstr_str(pattern, SL("/:int"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:int", 1); + INIT_ZVAL(wildcard); + ZVAL_STRING(&wildcard, "/:int", 0); PHALCON_INIT_VAR(int_pattern); ZVAL_STRING(int_pattern, "/([0-9]+)", 1); PHALCON_CPY_WRT(pattern_copy, compiled_pattern); PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, int_pattern, pattern_copy); + phalcon_fast_str_replace(compiled_pattern, &wildcard, int_pattern, pattern_copy); } } @@ -716,4 +716,3 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, reset){ PHALCON_MM_RESTORE(); } - diff --git a/ext/mvc/routerinterface.c b/ext/mvc/routerinterface.c index 697b3ed977d..a92c5132286 100644 --- a/ext/mvc/routerinterface.c +++ b/ext/mvc/routerinterface.c @@ -213,3 +213,9 @@ PHALCON_DOC_METHOD(Phalcon_Mvc_RouterInterface, getRouteById); */ PHALCON_DOC_METHOD(Phalcon_Mvc_RouterInterface, getRouteByName); +/** + * Returns whether controller name should not be mangled + * + * @return bool + */ +PHALCON_DOC_METHOD(Phalcon_Mvc_RouterInterface, isExactControllerName); diff --git a/ext/mvc/routerinterface.h b/ext/mvc/routerinterface.h index 5975e1b5736..475cbee10c5 100644 --- a/ext/mvc/routerinterface.h +++ b/ext/mvc/routerinterface.h @@ -109,6 +109,7 @@ PHALCON_INIT_FUNCS(phalcon_mvc_routerinterface_method_entry){ PHP_ABSTRACT_ME(Phalcon_Mvc_RouterInterface, getRoutes, NULL) PHP_ABSTRACT_ME(Phalcon_Mvc_RouterInterface, getRouteById, arginfo_phalcon_mvc_routerinterface_getroutebyid) PHP_ABSTRACT_ME(Phalcon_Mvc_RouterInterface, getRouteByName, arginfo_phalcon_mvc_routerinterface_getroutebyname) + PHP_ABSTRACT_ME(Phalcon_Mvc_RouterInterface, isExactControllerName, NULL) PHP_FE_END }; diff --git a/unit-tests/RouterMvcAnnotationsTest.php b/unit-tests/RouterMvcAnnotationsTest.php index efb32c57a2d..f3c345891a2 100644 --- a/unit-tests/RouterMvcAnnotationsTest.php +++ b/unit-tests/RouterMvcAnnotationsTest.php @@ -114,49 +114,49 @@ public function testRouterFullResources() array( 'uri' => '/products/save', 'method' => 'PUT', - 'controller' => 'products', + 'controller' => 'Products', 'action' => 'save', 'params' => array() ), array( 'uri' => '/products/save', 'method' => 'POST', - 'controller' => 'products', + 'controller' => 'Products', 'action' => 'save', 'params' => array() ), array( 'uri' => '/products/edit/100', 'method' => 'GET', - 'controller' => 'products', + 'controller' => 'Products', 'action' => 'edit', 'params' => array('id' => '100') ), array( 'uri' => '/products', 'method' => 'GET', - 'controller' => 'products', + 'controller' => 'Products', 'action' => 'index', 'params' => array() ), array( 'uri' => '/robots/edit/100', 'method' => 'GET', - 'controller' => 'robots', + 'controller' => 'Robots', 'action' => 'edit', 'params' => array('id' => '100') ), array( 'uri' => '/robots', 'method' => 'GET', - 'controller' => 'robots', + 'controller' => 'Robots', 'action' => 'index', 'params' => array() ), array( 'uri' => '/robots/save', 'method' => 'PUT', - 'controller' => 'robots', + 'controller' => 'Robots', 'action' => 'save', 'params' => array() ), @@ -170,6 +170,7 @@ public function testRouterFullResources() $this->assertEquals($router->getControllerName(), $route['controller']); $this->assertEquals($router->getActionName(), $route['action']); $this->assertEquals($router->getParams(), $route['params']); + $this->assertEquals($router->isExactControllerName(), true); } }