Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEEDS REVIEW] Fix #1040 #1153

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make tests pass
  • Loading branch information
sjinks committed Jan 21, 2014
commit aaea07eb5efa3368572276fe53b5d4ef0b8b59cc
76 changes: 41 additions & 35 deletions ext/mvc/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,39 +817,40 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){
PHALCON_GET_HKEY(part, ah1, hp1);
PHALCON_GET_HVALUE(position);

if (phalcon_array_isset_fetch(&match_position, matches, position)) {

/**
* Check if the part has a converter
*/
if (phalcon_array_isset_fetch(&converter, converters, part)) {
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);
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);
} else {
/**
* Apply the converters anyway
*/
if (phalcon_array_isset_fetch(&converter, converters, part)) {
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);
if (Z_TYPE_P(part) != IS_STRING || Z_STRVAL_P(part)[0] != '\0') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally used keys are strings and start with a binary 0 (so that they do not clash with user defined parameters)

if (phalcon_array_isset_fetch(&match_position, matches, position)) {
/**
* Check if the part has a converter
*/
if (phalcon_array_isset_fetch(&converter, converters, part)) {
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);
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);
} else {
/**
* Apply the converters anyway
*/
if (phalcon_array_isset_fetch(&converter, converters, part)) {
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);
}
}
}

Expand Down Expand Up @@ -912,9 +913,14 @@ PHP_METHOD(Phalcon_Mvc_Router, handle){
phalcon_update_property_this(this_ptr, SL("_module"), tmp TSRMLS_CC);
}

if (phalcon_array_isset_string_fetch(&exact, parts, SS("exact"))) {
if (phalcon_array_isset_string_fetch(&exact, parts, SS("\0exact"))) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$parts["\0exact"] is whether controller name should not be mangled

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);
phalcon_array_unset_string(&parts, SS("exact"), PH_SEPARATE);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions ext/mvc/router/annotations.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){
zval *empty_str, *real_action_name, *action_name;
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;
HashTable *ah0, *ah1;
HashPosition hp0, hp1;
zval **hd;
Expand Down Expand Up @@ -543,10 +543,13 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){
if (Z_TYPE_P(namespace) == IS_STRING) {
phalcon_array_update_string(&paths, ISL(namespace), &namespace, PH_COPY | PH_SEPARATE);
}

PHALCON_INIT_VAR(z_true);
ZVAL_TRUE(z_true);

phalcon_array_update_string(&paths, ISL(controller), &controller, PH_COPY | PH_SEPARATE);
phalcon_array_update_string(&paths, ISL(action), &action_name, PH_COPY | PH_SEPARATE);
add_assoc_bool_ex(paths, SS("exact"), 1);
phalcon_array_update_string(&paths, ISL(action), &action_name, PH_COPY);
phalcon_array_update_string(&paths, SL("\0exact"), &z_true, PH_COPY);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal property


PHALCON_INIT_VAR(position);
ZVAL_LONG(position, 0);
Expand Down
39 changes: 20 additions & 19 deletions ext/mvc/router/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){
PHALCON_CPY_WRT_CTOR(route_id, unique_id); /* route_id is now separated from unique_id */
phalcon_update_property_this(this_ptr, SL("_id"), route_id TSRMLS_CC);

/* increment_function() will increment the value of the static property as well */
increment_function(unique_id);
if (separate) {
phalcon_update_static_property_ce(phalcon_mvc_router_route_ce, SL("_uniqueId"), unique_id TSRMLS_CC);
Expand All @@ -199,7 +200,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();
Expand All @@ -223,78 +224,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);
}
}

Expand Down