Merge pull request #12294 from owncloud/route-postfix

Add route postfix to allow url versioning when only the http method changed
This commit is contained in:
Thomas Müller 2014-11-24 16:32:54 +01:00
commit ddacd7f900
2 changed files with 21 additions and 2 deletions

View File

@ -69,6 +69,12 @@ class RouteConfig {
$simpleRoutes = isset($routes['routes']) ? $routes['routes'] : array();
foreach ($simpleRoutes as $simpleRoute) {
$name = $simpleRoute['name'];
$postfix = '';
if (isset($simpleRoute['postfix'])) {
$postfix = $simpleRoute['postfix'];
}
$url = $simpleRoute['url'];
$verb = isset($simpleRoute['verb']) ? strtoupper($simpleRoute['verb']) : 'GET';
@ -84,7 +90,7 @@ class RouteConfig {
// register the route
$handler = new RouteActionHandler($this->container, $controllerName, $actionName);
$router = $this->router->create($this->appName.'.'.$controller.'.'.$action, $url)
$router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url)
->method($verb)
->action($handler);

View File

@ -54,6 +54,15 @@ class RoutingTest extends \Test\TestCase
$this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', array(), array('param' => 'foobar'));
}
public function testSimpleRouteWithPostfix()
{
$routes = array('routes' => array(
array('name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something')
));
$this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/folders/{folderId}/open', 'FoldersController', 'open', array(), array(), '_something');
}
/**
* @expectedException \UnexpectedValueException
@ -104,8 +113,12 @@ class RoutingTest extends \Test\TestCase
* @param string $controllerName
* @param string $actionName
*/
private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements=array(), array $defaults=array())
private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements=array(), array $defaults=array(), $postfix='')
{
if ($postfix) {
$name .= $postfix;
}
// route mocks
$route = $this->mockRoute($verb, $controllerName, $actionName, $requirements, $defaults);