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

[1.3.0] Fix return type of Phalcon\Mvc\Micro\Collection methods #1288

Merged
merged 2 commits into from Sep 24, 2013
Merged
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
Next Next commit
Fix #1130
  • Loading branch information
sjinks committed Sep 24, 2013
commit afd2abdb2aa73e1710835a8b39bc11e5c0906dcd
133 changes: 61 additions & 72 deletions ext/mvc/micro/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,27 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Collection){
* @param string $routePattern
* @param mixed $handler
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap){
void phalcon_mvc_collection_addmap(zval *this_ptr, zval *method, zval *route_pattern, zval *handler TSRMLS_DC) {

zval *method, *route_pattern, *handler, *handler_definition;
zval *handler_definition;

PHALCON_MM_GROW();
Z_ADDREF_P(method);
Z_ADDREF_P(route_pattern);
Z_ADDREF_P(handler);

phalcon_fetch_params(1, 3, 0, &method, &route_pattern, &handler);

PHALCON_INIT_VAR(handler_definition);
MAKE_STD_ZVAL(handler_definition);
array_init_size(handler_definition, 3);
phalcon_array_append(&handler_definition, method, PH_SEPARATE);
phalcon_array_append(&handler_definition, route_pattern, PH_SEPARATE);
phalcon_array_append(&handler_definition, handler, PH_SEPARATE);
add_next_index_zval(handler_definition, method);
add_next_index_zval(handler_definition, route_pattern);
add_next_index_zval(handler_definition, handler);
phalcon_update_property_array_append(this_ptr, SL("_handlers"), handler_definition TSRMLS_CC);

PHALCON_MM_RESTORE();
}

/**
* Sets a prefix for all routes added to the collection
*
* @param string $prefix
* @return Phalcon\Mvc\Micro\Collection
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, setPrefix){

Expand Down Expand Up @@ -143,7 +141,7 @@ PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandlers){
*
* @param mixed $handler
* @param boolean $lazy
* @return Phalcon\Mvc\Micro\Collection
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, setHandler){

Expand All @@ -155,7 +153,7 @@ PHP_METHOD(Phalcon_Mvc_Micro_Collection, setHandler){

if (!lazy) {
PHALCON_INIT_VAR(lazy);
ZVAL_BOOL(lazy, 0);
ZVAL_FALSE(lazy);
}

phalcon_update_property_this(this_ptr, SL("_handler"), handler TSRMLS_CC);
Expand All @@ -167,7 +165,7 @@ PHP_METHOD(Phalcon_Mvc_Micro_Collection, setHandler){
* Sets if the main handler must be lazy loaded
*
* @param boolean $lazy
* @return Phalcon\Mvc\Micro\Collection
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, setLazy){

Expand Down Expand Up @@ -206,165 +204,156 @@ PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandler){
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, map){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
ALLOC_INIT_ZVAL(method);
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is GET
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, get){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "GET", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is POST
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, post){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "POST", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is PUT
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, put){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "PUT", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is PATCH
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, patch){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "PATCH", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is HEAD
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, head){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "HEAD", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is DELETE
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, delete){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "DELETE", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

/**
* Maps a route to a handler that only matches if the HTTP method is OPTIONS
*
* @param string $routePattern
* @param callable $handler
* @return Phalcon\Mvc\Router\RouteInterface
* @return Phalcon\Mvc\Micro\CollectionInterface
*/
PHP_METHOD(Phalcon_Mvc_Micro_Collection, options){

zval *route_pattern, *handler, *method;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &route_pattern, &handler);
phalcon_fetch_params(0, 2, 0, &route_pattern, &handler);

PHALCON_INIT_VAR(method);
ALLOC_INIT_ZVAL(method);
ZVAL_STRING(method, "OPTIONS", 1);
phalcon_call_method_p3(return_value, this_ptr, "_addmap", method, route_pattern, handler);
RETURN_MM();
phalcon_mvc_collection_addmap(getThis(), method, route_pattern, handler TSRMLS_CC);
zval_ptr_dtor(&method);
RETURN_ZVAL(getThis(), 1, 0);
}

2 changes: 0 additions & 2 deletions ext/mvc/micro/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern zend_class_entry *phalcon_mvc_micro_collection_ce;

PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Collection);

PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap);
PHP_METHOD(Phalcon_Mvc_Micro_Collection, setPrefix);
PHP_METHOD(Phalcon_Mvc_Micro_Collection, getPrefix);
PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandlers);
Expand Down Expand Up @@ -92,7 +91,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_micro_collection_options, 0, 0, 2)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_mvc_micro_collection_method_entry){
PHP_ME(Phalcon_Mvc_Micro_Collection, _addMap, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Phalcon_Mvc_Micro_Collection, setPrefix, arginfo_phalcon_mvc_micro_collection_setprefix, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Micro_Collection, getPrefix, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Mvc_Micro_Collection, getHandlers, NULL, ZEND_ACC_PUBLIC)
Expand Down