diff options
author | Roeland Douma <rullzer@users.noreply.github.com> | 2016-07-19 12:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-19 12:21:14 +0200 |
commit | 13a25535d2c5c6b181ec31a41f76f825414a26f4 (patch) | |
tree | a9a3ae25e8c74823f324b55a66b040a83233a55b /lib/private/AppFramework/Routing/RouteConfig.php | |
parent | 544c3c156546d43912808ac18a13eba09f76aa3a (diff) | |
parent | c90a71a83bd97c03e78d33c12976c3fcf515bf44 (diff) | |
download | nextcloud-server-13a25535d2c5c6b181ec31a41f76f825414a26f4.tar.gz nextcloud-server-13a25535d2c5c6b181ec31a41f76f825414a26f4.zip |
Merge pull request #400 from nextcloud/ocs_appframework
OCS routes use AppFramework
Diffstat (limited to 'lib/private/AppFramework/Routing/RouteConfig.php')
-rw-r--r-- | lib/private/AppFramework/Routing/RouteConfig.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php index 64179336020..eca0051691f 100644 --- a/lib/private/AppFramework/Routing/RouteConfig.php +++ b/lib/private/AppFramework/Routing/RouteConfig.php @@ -62,6 +62,61 @@ class RouteConfig { // parse resources $this->processResources($this->routes); + + /* + * OCS routes go into a different collection + */ + $oldCollection = $this->router->getCurrentCollection(); + $this->router->useCollection($oldCollection.'.ocs'); + + // parse ocs simple routes + $this->processOCS($this->routes); + + $this->router->useCollection($oldCollection); + } + + private function processOCS(array $routes) { + $ocsRoutes = isset($routes['ocs']) ? $routes['ocs'] : []; + foreach ($ocsRoutes as $ocsRoute) { + $name = $ocsRoute['name']; + $postfix = ''; + + if (isset($ocsRoute['postfix'])) { + $postfix = $ocsRoute['postfix']; + } + + $url = $ocsRoute['url']; + $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; + + $split = explode('#', $name, 2); + if (count($split) != 2) { + throw new \UnexpectedValueException('Invalid route name'); + } + $controller = $split[0]; + $action = $split[1]; + + $controllerName = $this->buildControllerName($controller); + $actionName = $this->buildActionName($action); + + // register the route + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); + + $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) + ->method($verb) + ->action($handler); + + // optionally register requirements for route. This is used to + // tell the route parser how url parameters should be matched + if(array_key_exists('requirements', $ocsRoute)) { + $router->requirements($ocsRoute['requirements']); + } + + // optionally register defaults for route. This is used to + // tell the route parser how url parameters should be default valued + if(array_key_exists('defaults', $ocsRoute)) { + $router->defaults($ocsRoute['defaults']); + } + } } /** |