Skip to content

Commit

Permalink
Amended Route methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Jul 3, 2016
1 parent 7eb94b7 commit c16be70
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
- Fixed `Phalcon\Text:dynamic()` to allow custom separator [#11215](https://github.com/phalcon/cphalcon/issues/11215)
- Fixed `Phalcon\Validation::appendMessage` to allow append message to the empty stack [#10405](https://github.com/phalcon/cphalcon/issues/10405)
- Fixed `Phalcon\Session\Flash::getMessages`. Now it returns an empty array in case of non existent message type request [#11941](https://github.com/phalcon/cphalcon/issues/11941)
- Amended `Phalcon\Mvc\RouterInterface` and `Phalcon\Mvc\Router`. Added missed `addPurge`, `addTrace` and `addConnect` methods

# [2.0.13](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.13) (2016-05-19)
- Restored `Phalcon\Text::camelize` behavior [#11767](https://github.com/phalcon/cphalcon/issues/11767)
Expand Down
4 changes: 2 additions & 2 deletions phalcon/cli/router.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
Expand Down Expand Up @@ -447,7 +447,7 @@ class Router implements \Phalcon\Di\InjectionAwareInterface
}

/**
* Checks if the router macthes any of the defined routes
* Checks if the router matches any of the defined routes
*/
public function wasMatched() -> boolean
{
Expand Down
4 changes: 2 additions & 2 deletions phalcon/cli/routerinterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
Expand Down Expand Up @@ -92,7 +92,7 @@ interface RouterInterface
public function getMatches() -> array;

/**
* Check if the router macthes any of the defined routes
* Check if the router matches any of the defined routes
*/
public function wasMatched() -> boolean;

Expand Down
55 changes: 40 additions & 15 deletions phalcon/mvc/router.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
| Copyright (c) 2011-2016 Phalcon Team (https://phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
Expand Down Expand Up @@ -38,20 +38,21 @@ use Phalcon\Events\EventsAwareInterface;
* action of that controller should receive the request
*
*<code>
* use Phalcon\Mvc\Router;
*
* $router = new Router();
* $router = new Router();
*
* $router->add(
* "/documentation/{chapter}/{name}\.{type:[a-z]+}",
* array(
* "controller" => "documentation",
* "action" => "show"
* $router->add(
* '/documentation/{chapter}/{name}\.{type:[a-z]+}',
* [
* 'controller' => 'documentation',
* 'action' => 'show'
* )
* );
*
* $router->handle();
* $router->handle();
*
* echo $router->getControllerName();
* echo $router->getControllerName();
*</code>
*/
class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInterface
Expand Down Expand Up @@ -254,10 +255,10 @@ class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInt
* This method must not be used to set a 404 route
*
*<code>
* $router->setDefaults(array(
* 'module' => 'common',
* 'action' => 'index'
* ));
* $router->setDefaults([
* 'module' => 'common',
* 'action' => 'index'
* ]);
*</code>
*/
public function setDefaults(array! defaults) -> <RouterInterface>
Expand Down Expand Up @@ -310,10 +311,10 @@ class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInt
* Handles routing information received from the rewrite engine
*
*<code>
* //Read the info from the rewrite engine
* // Read the info from the rewrite engine
* $router->handle();
*
* //Manually passing an URL
* // Manually passing an URL
* $router->handle('/posts/edit/1');
*</code>
*/
Expand Down Expand Up @@ -761,6 +762,30 @@ class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInt
return this->add(pattern, paths, "HEAD", position);
}

/**
* Adds a route to the router that only match if the HTTP method is PURGE (Squid and Varnish support)
*/
public function addPurge(string! pattern, var paths = null, var position = Router::POSITION_LAST) -> <RouteInterface>
{
return this->add(pattern, paths, "PURGE", position);
}

/**
* Adds a route to the router that only match if the HTTP method is TRACE
*/
public function addTrace(string! pattern, var paths = null, var position = Router::POSITION_LAST) -> <RouteInterface>
{
return this->add(pattern, paths, "TRACE", position);
}

/**
* Adds a route to the router that only match if the HTTP method is CONNECT
*/
public function addConnect(string! pattern, var paths = null, var position = Router::POSITION_LAST) -> <RouteInterface>
{
return this->add(pattern, paths, "CONNECT", position);
}

/**
* Mounts a group of routes in the router
*/
Expand Down
15 changes: 15 additions & 0 deletions phalcon/mvc/routerinterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ interface RouterInterface
*/
public function addHead(string! pattern, var paths = null) -> <RouteInterface>;

/**
* Adds a route to the router that only match if the HTTP method is PURGE (Squid and Varnish support)
*/
public function addPurge(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>;

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

/**
* Mounts a group of routes in the router
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/_proxies/Mvc/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ public function addHead($pattern, $paths = null, $position = Router::POSITION_LA
return parent::addHead($pattern, $paths, $position);
}

public function addPurge($pattern, $paths = null, $position = Router::POSITION_LAST)
{
return parent::addPurge($pattern, $paths, $position);
}

public function addTrace($pattern, $paths = null, $position = Router::POSITION_LAST)
{
return parent::addTrace($pattern, $paths, $position);
}

public function addConnect($pattern, $paths = null, $position = Router::POSITION_LAST)
{
return parent::addConnect($pattern, $paths, $position);
}

public function mount(GroupInterface $group)
{
return parent::mount($group);
Expand Down
38 changes: 37 additions & 1 deletion tests/unit/Mvc/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ function ($method, $uri, $controller, $action, $params) {
'action' => 'index'
]);

$router->addPurge('/docs/index', [
'controller' => 'documentation9',
'action' => 'index'
]);

$router->addTrace('/docs/index', [
'controller' => 'documentation10',
'action' => 'index'
]);

$router->addConnect('/docs/index', [
'controller' => 'documentation11',
'action' => 'index'
]);

$_SERVER['REQUEST_METHOD'] = $method;
$router->handle($uri);

Expand Down Expand Up @@ -750,7 +765,28 @@ protected function methodProvider()
'controller' => 'documentation8',
'action' => 'index',
'params' => []
]
],
'PURGE' => [
'method' => 'PURGE',
'uri' => '/docs/index',
'controller' => 'documentation9',
'action' => 'index',
'params' => []
],
'TRACE' => [
'method' => 'TRACE',
'uri' => '/docs/index',
'controller' => 'documentation10',
'action' => 'index',
'params' => []
],
'CONNECT' => [
'method' => 'CONNECT',
'uri' => '/docs/index',
'controller' => 'documentation11',
'action' => 'index',
'params' => []
],
];
}

Expand Down

0 comments on commit c16be70

Please sign in to comment.