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

yaf_route_simple_assemble complete #8

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions routes/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
};
/* }}} */
Expand Down
8 changes: 8 additions & 0 deletions routes/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
/* }}} */
Expand Down
8 changes: 8 additions & 0 deletions routes/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
/* }}} */
Expand Down
8 changes: 8 additions & 0 deletions routes/rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
/* }}} */
Expand Down
118 changes: 118 additions & 0 deletions routes/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}
};
/* }}} */
Expand Down
8 changes: 8 additions & 0 deletions routes/static.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
/* }}} */
Expand Down
8 changes: 8 additions & 0 deletions routes/supervar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
/* }}} */
Expand Down
27 changes: 27 additions & 0 deletions tests/051.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Check for Yaf_Simple_Router_assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--FILE--
<?php

$router = new Yaf_Router();

$route = new Yaf_Route_Simple('m', 'c', 'a');

$router->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"
1 change: 1 addition & 0 deletions tests/short_tag_test.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?=$name?>
3 changes: 3 additions & 0 deletions yaf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php



$br = (php_sapi_name() == "cli")? "":"<br>";

if(!extension_loaded('ap')) {
Expand Down