Skip to content

Commit

Permalink
Fix #1275
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Oct 19, 2013
1 parent b617bab commit d40c88a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
12 changes: 2 additions & 10 deletions ext/mvc/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
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, *real_controller_name;
zval *content;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -466,14 +466,6 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){
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 @@ -485,7 +477,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", real_controller_name);
phalcon_call_method_p2_noret(dispatcher, "setcontrollername", controller_name, exact);
phalcon_call_method_p1_noret(dispatcher, "setactionname", action_name);
phalcon_call_method_p1_noret(dispatcher, "setparams", params);

Expand Down
39 changes: 33 additions & 6 deletions ext/mvc/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include "kernel/main.h"
#include "kernel/memory.h"

#include "kernel/concat.h"
#include "kernel/object.h"
#include "kernel/fcall.h"
#include "kernel/exception.h"
Expand Down Expand Up @@ -72,6 +72,7 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher){
zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_handlerSuffix"), "Controller", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_defaultHandler"), "index", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_defaultAction"), "index", ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_mvc_dispatcher_ce, SL("_isExactControllerName"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);

zend_class_implements(phalcon_mvc_dispatcher_ce TSRMLS_CC, 2, phalcon_dispatcherinterface_ce, phalcon_mvc_dispatcherinterface_ce);

Expand Down Expand Up @@ -115,12 +116,22 @@ PHP_METHOD(Phalcon_Mvc_Dispatcher, setDefaultController){
*/
PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerName){

zval *controller_name;
zval *controller_name, *is_exact = NULL;

phalcon_fetch_params(0, 1, 0, &controller_name);

phalcon_update_property_this(this_ptr, SL("_handlerName"), controller_name TSRMLS_CC);
phalcon_fetch_params(0, 1, 1, &controller_name, &is_exact);

if (is_exact && zend_is_true(is_exact)) {
zval *name;
MAKE_STD_ZVAL(name);
PHALCON_CONCAT_SV(name, "\\", controller_name);
phalcon_update_property_this(this_ptr, SL("_handlerName"), name TSRMLS_CC);
zval_ptr_dtor(&name);
phalcon_update_property_bool(this_ptr, SL("_isExactControllerName"), 1 TSRMLS_CC);
}
else {
phalcon_update_property_this(this_ptr, SL("_handlerName"), controller_name TSRMLS_CC);
phalcon_update_property_bool(this_ptr, SL("_isExactControllerName"), 0 TSRMLS_CC);
}
}

/**
Expand All @@ -130,8 +141,24 @@ PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerName){
*/
PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerName){

zval *is_exact;
int i_exact;

phalcon_read_property_this(&is_exact, getThis(), SL("_isExactControllerName"), PH_NOISY TSRMLS_CC);
i_exact = zend_is_true(is_exact);
zval_ptr_dtor(&is_exact);

RETURN_MEMBER(this_ptr, "_handlerName");
if (!i_exact) {
RETURN_MEMBER(this_ptr, "_handlerName");
}

phalcon_return_property_quick(return_value, getThis(), SL("_handlerName"), zend_inline_hash_func(SS("_handlerName")) TSRMLS_CC);
if (likely(Z_TYPE_P(return_value) == IS_STRING) && Z_STRLEN_P(return_value) > 1) {
char *c = Z_STRVAL_P(return_value);
int len = Z_STRLEN_P(return_value);
memmove(c, c+1, len-1);
c[len] = 0;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions ext/mvc/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_dispatcher_setcontrollername, 0, 0, 1)
ZEND_ARG_INFO(0, controllerName)
ZEND_ARG_INFO(0, isExact)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_mvc_dispatcher_method_entry){
Expand Down
1 change: 1 addition & 0 deletions ext/mvc/dispatcherinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ PHALCON_DOC_METHOD(Phalcon_Mvc_DispatcherInterface, setDefaultController);
* Sets the controller name to be dispatched
*
* @param string $controllerName
* @param bool $isExact If true, the name should not be mangled in any way
*/
PHALCON_DOC_METHOD(Phalcon_Mvc_DispatcherInterface, setControllerName);

Expand Down
1 change: 1 addition & 0 deletions ext/mvc/dispatcherinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_dispatcherinterface_setcontrollername, 0, 0, 1)
ZEND_ARG_INFO(0, controllerName)
ZEND_ARG_INFO(0, isExact)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_mvc_dispatcherinterface_method_entry){
Expand Down

0 comments on commit d40c88a

Please sign in to comment.