]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow registering of OCS routes with the appframework
authorRoeland Jago Douma <rullzer@owncloud.com>
Tue, 17 May 2016 08:11:27 +0000 (10:11 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 18 Jul 2016 09:09:04 +0000 (11:09 +0200)
lib/private/AppFramework/Routing/RouteConfig.php

index 64179336020e0b375e5b944e240130c0e1977874..d4b4ec038ad9c8a2f4a687e313a7bf5841608a83 100644 (file)
@@ -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']);
+                       }
+               }
        }
 
        /**