diff --git a/routes/interface.c b/routes/interface.c index ffa153cd..a2f476e1 100644 --- a/routes/interface.c +++ b/routes/interface.c @@ -31,6 +31,11 @@ YAF_BEGIN_ARG_INFO_EX(yaf_route_route_arginfo, 0, 0, 1) YAF_ARG_INFO(0, request) YAF_END_ARG_INFO() + +YAF_BEGIN_ARG_INFO_EX(yaf_route_assemble_arginfo, 0, 0, 1) + YAF_ARG_INFO(0, mvc) + YAF_ARG_INFO(0, query) +YAF_END_ARG_INFO() /* }}} */ zend_class_entry *yaf_route_ce; @@ -138,6 +143,7 @@ yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC) */ zend_function_entry yaf_route_methods[] = { PHP_ABSTRACT_ME(yaf_route, route, yaf_route_route_arginfo) + PHP_ABSTRACT_ME(yaf_route, assemble, yaf_route_assemble_arginfo) {NULL, NULL, NULL} }; /* }}} */ diff --git a/routes/map.c b/routes/map.c index c47edf90..33c5c136 100644 --- a/routes/map.c +++ b/routes/map.c @@ -159,11 +159,19 @@ PHP_METHOD(yaf_route_map, __construct) { } /* }}} */ +/** {{{ proto public Yaf_Route_Map::assemble(zval *mvc, zval *query) +*/ +PHP_METHOD(yaf_route_map, assemble) { + +} +/* }}} */ + /** {{{ yaf_route_map_methods */ zend_function_entry yaf_route_map_methods[] = { PHP_ME(yaf_route_map, __construct, yaf_route_map_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(yaf_route_map, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_route_map, assemble, yaf_route_assemble_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/routes/regex.c b/routes/regex.c index 29cc4eb0..777a57bf 100644 --- a/routes/regex.c +++ b/routes/regex.c @@ -232,11 +232,19 @@ PHP_METHOD(yaf_route_regex, __construct) { } /** }}} */ +/** {{{ proto public Yaf_Route_regex::assemble(zval *mvc, zval *query) +*/ +PHP_METHOD(yaf_route_regex, assemble) { + +} +/* }}} */ + /** {{{ yaf_route_regex_methods */ zend_function_entry yaf_route_regex_methods[] = { PHP_ME(yaf_route_regex, __construct, yaf_route_regex_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(yaf_route_regex, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_route_regex, assemble, yaf_route_assemble_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/routes/rewrite.c b/routes/rewrite.c index b6598877..3c0aa2ac 100644 --- a/routes/rewrite.c +++ b/routes/rewrite.c @@ -287,11 +287,19 @@ PHP_METHOD(yaf_route_rewrite, __construct) { } /** }}} */ +/** {{{ proto public Yaf_Route_rewrite::assemble(zval *mvc, zval *query) +*/ +PHP_METHOD(yaf_route_rewrite, assemble) { + +} +/* }}} */ + /** {{{ yaf_route_rewrite_methods */ zend_function_entry yaf_route_rewrite_methods[] = { PHP_ME(yaf_route_rewrite, __construct, yaf_route_rewrite_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(yaf_route_rewrite, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_route_rewrite, assemble, yaf_route_assemble_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/routes/simple.c b/routes/simple.c index 8ae3ad80..ab2a0f7a 100644 --- a/routes/simple.c +++ b/routes/simple.c @@ -81,6 +81,108 @@ yaf_route_t * yaf_route_simple_instance(yaf_route_t *this_ptr, zval *module, zva } /* }}} */ +/** {{{ zval * yaf_route_simple_assemble(zval *mvc, zval *query TSRMLS_DC) + */ +zval * yaf_route_simple_assemble(yaf_route_t *this_ptr, zval *mvc, zval *query TSRMLS_DC) { + char *tvalue; + zval *nmodule, *ncontroller, *naction; + zval *uri; + + MAKE_STD_ZVAL(uri); + tvalue = emalloc(sizeof("?")); + tvalue[0] = '\0'; + strcat(tvalue, "?"); + + nmodule = zend_read_property(yaf_route_simple_ce, this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_MODULE), 1 TSRMLS_CC); + ncontroller = zend_read_property(yaf_route_simple_ce, this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER), 1 TSRMLS_CC); + naction = zend_read_property(yaf_route_simple_ce, this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_ACTION), 1 TSRMLS_CC); + + do { + zval **tmp; + char *tsprintf; + uint tlen; + + if (zend_hash_find(Z_ARRVAL_P(mvc), Z_STRVAL_P(nmodule), Z_STRLEN_P(nmodule) + 1, (void **)&tmp) == SUCCESS) { + tlen = snprintf(NULL, 0, "%s=%s&", Z_STRVAL_P(nmodule), Z_STRVAL_PP(tmp)); + if (!(tsprintf = emalloc((tlen + 1) * sizeof(char)))) { + break; + } + tlen = snprintf(tsprintf, tlen + 1, "%s=%s&", Z_STRVAL_P(nmodule), Z_STRVAL_PP(tmp)); + if (tlen) { + tvalue = erealloc(tvalue, strlen(tvalue) + tlen + 1); + strcat(tvalue, tsprintf); + } + efree(tsprintf); + } + + if (zend_hash_find(Z_ARRVAL_P(mvc), Z_STRVAL_P(ncontroller), Z_STRLEN_P(ncontroller) + 1, (void **)&tmp) == FAILURE) { + yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "%s", "You need to specify the controller"); + break; + } + + tlen = snprintf(NULL, 0, "%s=%s&", Z_STRVAL_P(ncontroller), Z_STRVAL_PP(tmp)); + if (!(tsprintf = emalloc((tlen + 1) * sizeof(char)))) { + break; + } + tlen = snprintf(tsprintf, tlen + 1, "%s=%s&", Z_STRVAL_P(ncontroller), Z_STRVAL_PP(tmp)); + if (tlen) { + tvalue = erealloc(tvalue, strlen(tvalue) + tlen + 1); + strcat(tvalue, tsprintf); + } + efree(tsprintf); + + if(zend_hash_find(Z_ARRVAL_P(mvc), Z_STRVAL_P(naction), Z_STRLEN_P(naction) + 1, (void **)&tmp) == FAILURE) { + yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "%s", "You need to specify the action"); + break; + } + + tlen = snprintf(NULL, 0, "%s=%s", Z_STRVAL_P(naction), Z_STRVAL_PP(tmp)); + if (!(tsprintf = emalloc((tlen + 1) * sizeof(char)))) { + break; + } + tlen = snprintf(tsprintf, tlen + 1, "%s=%s", Z_STRVAL_P(naction), Z_STRVAL_PP(tmp)); + if (tlen) { + tvalue = erealloc(tvalue, strlen(tvalue) + tlen + 1); + strcat(tvalue, tsprintf); + } + efree(tsprintf); + + if ( IS_ARRAY == Z_TYPE_P(query)) { + uint key_type, key_len; + char *key; + ulong key_idx; + + for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(query)); + zend_hash_get_current_data(Z_ARRVAL_P(query), (void **)&tmp) == SUCCESS; + zend_hash_move_forward(Z_ARRVAL_P(query))) { + + if (IS_STRING == Z_TYPE_PP(tmp) + && HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(query), &key, &key_len, &key_idx, 0, NULL)) { + + tlen = snprintf(NULL, 0, "&%s=%s", key, Z_STRVAL_PP(tmp)); + if (!(tsprintf = emalloc((tlen + 1) * sizeof(char)))) { + break; + } + tlen = snprintf(tsprintf, tlen + 1, "&%s=%s", key, Z_STRVAL_PP(tmp)); + if (tlen) { + tvalue = erealloc(tvalue, strlen(tvalue) + tlen + 1); + strcat(tvalue, tsprintf); + } + efree(tsprintf); + } + } + } + + ZVAL_STRING(uri, tvalue, 1); + efree(tvalue); + return uri; + } while (0); + + efree(tvalue); + ZVAL_NULL(uri); + return uri; +} + /** {{{ proto public Yaf_Route_Simple::route(Yaf_Request $req) */ PHP_METHOD(yaf_route_simple, route) { @@ -114,11 +216,27 @@ PHP_METHOD(yaf_route_simple, __construct) { } /* }}} */ +/** {{{ proto public Yaf_Route_Simple::assemble(zval *mvc, zval *query) +*/ +PHP_METHOD(yaf_route_simple, assemble) { + zval *mvc, *query; + zval *return_uri; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &mvc, &query) == FAILURE) { + return; + } else { + return_uri = yaf_route_simple_assemble(getThis(), mvc, query TSRMLS_CC); + RETURN_ZVAL(return_uri, 1, 0); + } +} +/* }}} */ + /** {{{ yaf_route_simple_methods */ zend_function_entry yaf_route_simple_methods[] = { PHP_ME(yaf_route_simple, __construct, yaf_route_simple_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(yaf_route_simple, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_route_simple, assemble, yaf_route_assemble_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/routes/static.c b/routes/static.c index 02703a41..a82e1ae3 100644 --- a/routes/static.c +++ b/routes/static.c @@ -182,11 +182,19 @@ PHP_METHOD(yaf_route_static, match) { } /* }}} */ +/** {{{ proto public Yaf_Route_Static::assemble(zval *mvc, zval *query) +*/ +PHP_METHOD(yaf_route_static, assemble) { + +} +/* }}} */ + /** {{{ yaf_route_static_methods */ zend_function_entry yaf_route_static_methods[] = { PHP_ME(yaf_route_static, match, yaf_route_static_match_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_route_static, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_route_static, assemble, yaf_route_assemble_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/routes/supervar.c b/routes/supervar.c index c2a7cb86..0d9abcdd 100644 --- a/routes/supervar.c +++ b/routes/supervar.c @@ -101,11 +101,19 @@ PHP_METHOD(yaf_route_supervar, __construct) { } /** }}} */ +/** {{{ proto public Yaf_Route_Supervar::assemble(zval *mvc, zval *query) +*/ +PHP_METHOD(yaf_route_supervar, assemble) { + +} +/* }}} */ + /** {{{ yaf_route_supervar_methods */ zend_function_entry yaf_route_supervar_methods[] = { PHP_ME(yaf_route_supervar, __construct, yaf_route_supervar_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(yaf_route_supervar, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_route_supervar, assemble, yaf_route_assemble_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/tests/051.phpt b/tests/051.phpt new file mode 100644 index 00000000..cd27e08f --- /dev/null +++ b/tests/051.phpt @@ -0,0 +1,27 @@ +--TEST-- +Check for Yaf_Simple_Router_assemble +--SKIPIF-- + +--FILE-- +addRoute("simple", $route); + +var_dump($router->getRoute('simple')->assemble( + array( + 'a' => 'yafaction', + 'tkey' => 'tval', + 'c' => 'yafcontroller', + 'm' => 'yafmodule' + ), + array( + 'tkey1' => 'tval1', + 'tkey2' => 'tval2' + ) +)); +--EXPECTF-- +string(64) "?m=yafmodule&c=yafcontroller&a=yafaction&tkey1=tval1&tkey2=tval2" diff --git a/tests/short_tag_test.phtml b/tests/short_tag_test.phtml new file mode 100644 index 00000000..1a6fc753 --- /dev/null +++ b/tests/short_tag_test.phtml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/yaf.php b/yaf.php index 348268e6..55da9ab2 100644 --- a/yaf.php +++ b/yaf.php @@ -1,4 +1,7 @@ "; if(!extension_loaded('ap')) {