diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-11-24 16:32:54 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-11-24 16:32:54 +0100 |
commit | ddacd7f9007d8e79415ae1e850588f92882b8329 (patch) | |
tree | ef0ee77f9a2936208fc523ec1bcb834cb35df0b5 | |
parent | 168fce0b182e69d1364e4432178a8131961d6583 (diff) | |
parent | 4e90c44301cdacc85f31259bff887b035a1b9716 (diff) | |
download | nextcloud-server-ddacd7f9007d8e79415ae1e850588f92882b8329.tar.gz nextcloud-server-ddacd7f9007d8e79415ae1e850588f92882b8329.zip |
Merge pull request #12294 from owncloud/route-postfix
Add route postfix to allow url versioning when only the http method changed
-rw-r--r-- | lib/private/appframework/routing/routeconfig.php | 8 | ||||
-rw-r--r-- | tests/lib/appframework/routing/RoutingTest.php | 15 |
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/private/appframework/routing/routeconfig.php b/lib/private/appframework/routing/routeconfig.php index 91687b9c83c..9816b062b8d 100644 --- a/lib/private/appframework/routing/routeconfig.php +++ b/lib/private/appframework/routing/routeconfig.php @@ -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); diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php index 276307680af..4ee3ed58807 100644 --- a/tests/lib/appframework/routing/RoutingTest.php +++ b/tests/lib/appframework/routing/RoutingTest.php @@ -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); |