Commit ddacd7f9 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #12294 from owncloud/route-postfix

Add route postfix to allow url versioning when only the http method changed
parents 168fce0b 4e90c443
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment