Skip to content

Commit

Permalink
Added addConnect(), addPurge() and addTrace() to Router Group (#14001)
Browse files Browse the repository at this point in the history
* Removed unused variable.

* Added addConnect(), addPurge() and addTrace() to Router Group.

* Added tests for Mvc\Router\Group.
  • Loading branch information
SidRoberts authored and niden committed Apr 19, 2019
1 parent 85a60f2 commit 23e92d3
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `chunk()`, `first()`, `firstKey()`, `flatten()`, `group()`, `isUnique()`, `last()`, `lastKey()`, `order()`, `pluck()`, `sliceLeft()`, `sliceRight()`, `split()`, `tail()`, `validateAll()`, `validateAny()` to `Phalcon\Helper\Arr` [#13954](https://github.com/phalcon/cphalcon/pull/13954)
- Added `camelize()`, `concat()`, `countVowels()`, `decapitalize()`, `dynamic()`, `endsWith()`, `firstStringBetween()`, `includes()`, `increment()`, `isAnagram()`, `isLower()`, `isPalindrome()`, `isUpper()`, `lower()`, `random()`, `reduceSlashes()`, `startsWith()`, `uncamelize()`, `underscore()`, `upper()` to `Phalcon\Helper\Str` [#13954](https://github.com/phalcon/cphalcon/pull/13954)
- Added `Phalcon\Mvc\Model\Query\BuilderInterface::getModels()` returns the models involved in the query
- Added `addConnect()`, `addPurge()` and `addTrace()` to `Phalcon\Mvc\Router\Group` and its interface. [#14001](https://github.com/phalcon/cphalcon/pull/14001)

## Changed
- Refactored `Phalcon\Events\Manager` to only use `SplPriorityQueue` to store events. [#13924](https://github.com/phalcon/cphalcon/pull/13924)
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Annotations/Reflection.zep
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Reflection
*/
public function getMethodsAnnotations() -> <Collection[]> | bool
{
var reflectionMethods, collections, methodName, reflectionMethod;
var reflectionMethods, methodName, reflectionMethod;

if this->methodAnnotations === null {
if fetch reflectionMethods, this->reflectionData["methods"] {
Expand Down
30 changes: 30 additions & 0 deletions phalcon/Mvc/Router/Group.zep
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ class Group implements GroupInterface
return this->addRoute(pattern, paths, httpMethods);
}

/**
* Adds a route to the router that only match if the HTTP method is CONNECT
*
* @param string|array paths
*/
public function addConnect(string! pattern, var paths = null) -> <RouteInterface>
{
return this->addRoute(pattern, paths, "CONNECT");
}

/**
* Adds a route to the router that only match if the HTTP method is DELETE
*
Expand Down Expand Up @@ -152,6 +162,16 @@ class Group implements GroupInterface
return this->addRoute(pattern, paths, "POST");
}

/**
* Adds a route to the router that only match if the HTTP method is PURGE
*
* @param string|array paths
*/
public function addPurge(string! pattern, var paths = null) -> <RouteInterface>
{
return this->addRoute(pattern, paths, "PURGE");
}

/**
* Adds a route to the router that only match if the HTTP method is PUT
*
Expand All @@ -162,6 +182,16 @@ class Group implements GroupInterface
return this->addRoute(pattern, paths, "PUT");
}

/**
* Adds a route to the router that only match if the HTTP method is TRACE
*
* @param string|array paths
*/
public function addTrace(string! pattern, var paths = null) -> <RouteInterface>
{
return this->addRoute(pattern, paths, "TRACE");
}

/**
* Sets a callback that is called if the route is matched.
* The developer can implement any arbitrary conditions here
Expand Down
19 changes: 17 additions & 2 deletions phalcon/Mvc/Router/GroupInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,20 @@ interface GroupInterface
public function add(string! pattern, var paths = null, var httpMethods = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is GET
* Adds a route to the router that only match if the HTTP method is CONNECT
*/
public function addGet(string! pattern, var paths = null) -> <RouteInterface>;
public function addConnect(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is DELETE
*/
public function addDelete(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is GET
*/
public function addGet(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is HEAD
*/
Expand All @@ -100,11 +105,21 @@ interface GroupInterface
*/
public function addPost(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is PURGE
*/
public function addPurge(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is PUT
*/
public function addPut(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is TRACE
*/
public function addTrace(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Sets a callback that is called if the route is matched.
* The developer can implement any arbitrary conditions here
Expand Down
47 changes: 44 additions & 3 deletions tests/integration/Mvc/Router/Group/AddDeleteCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,64 @@
namespace Phalcon\Test\Integration\Mvc\Router\Group;

use IntegrationTester;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Router\Group;
use Phalcon\Test\Fixtures\Traits\RouterTrait;

/**
* Class AddDeleteCest
*/
class AddDeleteCest
{
use RouterTrait;

/**
* Tests Phalcon\Mvc\Router\Group :: addDelete()
*
* @param IntegrationTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
* @author Sid Roberts <sid@sidroberts.co.uk>
* @since 2019-04-17
*/
public function mvcRouterGroupAddDelete(IntegrationTester $I)
{
$I->wantToTest('Mvc\Router\Group - addDelete()');
$I->skipTest('Need implementation');

$router = $this->getRouter(false);

$group = new Group();

$group->addDelete(
'/docs/index',
[
'controller' => 'documentation6',
'action' => 'index',
]
);

$router->mount($group);



$_SERVER['REQUEST_METHOD'] = 'DELETE';

$router->handle('/docs/index');



$I->assertEquals(
'documentation6',
$router->getControllerName()
);

$I->assertEquals(
'index',
$router->getActionName()
);

$I->assertEquals(
[],
$router->getParams()
);
}
}
49 changes: 45 additions & 4 deletions tests/integration/Mvc/Router/Group/AddGetCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,64 @@
namespace Phalcon\Test\Integration\Mvc\Router\Group;

use IntegrationTester;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Router\Group;
use Phalcon\Test\Fixtures\Traits\RouterTrait;

/**
* Class AddGetCest
*/
class AddGetCest
{
use RouterTrait;

/**
* Tests Phalcon\Mvc\Router\Group :: addGet()
*
* @param IntegrationTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
* @author Sid Roberts <sid@sidroberts.co.uk>
* @since 2019-04-17
*/
public function mvcRouterGroupAddGet(IntegrationTester $I)
{
$I->wantToTest('Mvc\Router\Group - addGet()');
$I->skipTest('Need implementation');
$I->wantToTest('Mvc\Router - addGet()');

$router = $this->getRouter(false);

$group = new Group();

$group->addGet(
'/docs/index',
[
'controller' => 'documentation4',
'action' => 'index',
]
);

$router->mount($group);



$_SERVER['REQUEST_METHOD'] = 'GET';

$router->handle('/docs/index');



$I->assertEquals(
'documentation4',
$router->getControllerName()
);

$I->assertEquals(
'index',
$router->getActionName()
);

$I->assertEquals(
[],
$router->getParams()
);
}
}
49 changes: 45 additions & 4 deletions tests/integration/Mvc/Router/Group/AddHeadCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,64 @@
namespace Phalcon\Test\Integration\Mvc\Router\Group;

use IntegrationTester;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Router\Group;
use Phalcon\Test\Fixtures\Traits\RouterTrait;

/**
* Class AddHeadCest
*/
class AddHeadCest
{
use RouterTrait;

/**
* Tests Phalcon\Mvc\Router\Group :: addHead()
*
* @param IntegrationTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
* @author Sid Roberts <sid@sidroberts.co.uk>
* @since 2019-04-17
*/
public function mvcRouterGroupAddHead(IntegrationTester $I)
{
$I->wantToTest('Mvc\Router\Group - addHead()');
$I->skipTest('Need implementation');
$I->wantToTest('Mvc\Router - addHead()');

$router = $this->getRouter(false);

$group = new Group();

$group->addHead(
'/docs/index',
[
'controller' => 'documentation8',
'action' => 'index',
]
);

$router->mount($group);



$_SERVER['REQUEST_METHOD'] = 'HEAD';

$router->handle('/docs/index');



$I->assertEquals(
'documentation8',
$router->getControllerName()
);

$I->assertEquals(
'index',
$router->getActionName()
);

$I->assertEquals(
[],
$router->getParams()
);
}
}
49 changes: 45 additions & 4 deletions tests/integration/Mvc/Router/Group/AddOptionsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,64 @@
namespace Phalcon\Test\Integration\Mvc\Router\Group;

use IntegrationTester;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Router\Group;
use Phalcon\Test\Fixtures\Traits\RouterTrait;

/**
* Class AddOptionsCest
*/
class AddOptionsCest
{
use RouterTrait;

/**
* Tests Phalcon\Mvc\Router\Group :: addOptions()
*
* @param IntegrationTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
* @author Sid Roberts <sid@sidroberts.co.uk>
* @since 2019-04-17
*/
public function mvcRouterGroupAddOptions(IntegrationTester $I)
{
$I->wantToTest('Mvc\Router\Group - addOptions()');
$I->skipTest('Need implementation');
$I->wantToTest('Mvc\Router - addOptions()');

$router = $this->getRouter(false);

$group = new Group();

$group->addOptions(
'/docs/index',
[
'controller' => 'documentation7',
'action' => 'index',
]
);

$router->mount($group);



$_SERVER['REQUEST_METHOD'] = 'OPTIONS';

$router->handle('/docs/index');



$I->assertEquals(
'documentation7',
$router->getControllerName()
);

$I->assertEquals(
'index',
$router->getActionName()
);

$I->assertEquals(
[],
$router->getParams()
);
}
}
Loading

0 comments on commit 23e92d3

Please sign in to comment.