diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd0bb0e1ca..da256eafd33 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/phalcon/cli/router.zep b/phalcon/cli/router.zep index 630c7d8eebe..300884677b6 100644 --- a/phalcon/cli/router.zep +++ b/phalcon/cli/router.zep @@ -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. | @@ -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 { diff --git a/phalcon/cli/routerinterface.zep b/phalcon/cli/routerinterface.zep index 0b08557989d..3295c2e24c2 100644 --- a/phalcon/cli/routerinterface.zep +++ b/phalcon/cli/routerinterface.zep @@ -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. | @@ -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; diff --git a/phalcon/mvc/router.zep b/phalcon/mvc/router.zep index 0ffe60c73d3..6f994870e2b 100755 --- a/phalcon/mvc/router.zep +++ b/phalcon/mvc/router.zep @@ -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. | @@ -38,20 +38,21 @@ use Phalcon\Events\EventsAwareInterface; * action of that controller should receive the request * * + * 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(); * */ class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInterface @@ -254,10 +255,10 @@ class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInt * This method must not be used to set a 404 route * * - * $router->setDefaults(array( - * 'module' => 'common', - * 'action' => 'index' - * )); + * $router->setDefaults([ + * 'module' => 'common', + * 'action' => 'index' + * ]); * */ public function setDefaults(array! defaults) -> @@ -310,10 +311,10 @@ class Router implements InjectionAwareInterface, RouterInterface, EventsAwareInt * Handles routing information received from the rewrite engine * * - * //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'); * */ @@ -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) -> + { + 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) -> + { + 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) -> + { + return this->add(pattern, paths, "CONNECT", position); + } + /** * Mounts a group of routes in the router */ diff --git a/phalcon/mvc/routerinterface.zep b/phalcon/mvc/routerinterface.zep index ce45aca473d..a31b0f9f298 100644 --- a/phalcon/mvc/routerinterface.zep +++ b/phalcon/mvc/routerinterface.zep @@ -95,6 +95,21 @@ interface RouterInterface */ public function addHead(string! pattern, var paths = null) -> ; + /** + * 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) -> ; + + /** + * Adds a route to the router that only match if the HTTP method is TRACE + */ + public function addTrace(string! pattern, var paths = null) -> ; + + /** + * Adds a route to the router that only match if the HTTP method is CONNECT + */ + public function addConnect(string! pattern, var paths = null) -> ; + /** * Mounts a group of routes in the router */ diff --git a/tests/_proxies/Mvc/Router.php b/tests/_proxies/Mvc/Router.php index 7beaf7c9b9e..e34067c8772 100644 --- a/tests/_proxies/Mvc/Router.php +++ b/tests/_proxies/Mvc/Router.php @@ -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); diff --git a/tests/unit/Mvc/RouterTest.php b/tests/unit/Mvc/RouterTest.php index a1e74b87c1d..a87e6a7f62a 100644 --- a/tests/unit/Mvc/RouterTest.php +++ b/tests/unit/Mvc/RouterTest.php @@ -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); @@ -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' => [] + ], ]; }