Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-05-17 11:11:27 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2016-07-18 12:09:04 +0300
commit1ff4b7f63d7dd80cb92a35beb95df2e0b6891476 (patch)
tree6e6142ca3e566402d38e6ed985df31bdaf6a4be8 /lib
parent5157c5a9c4b08518dc86e5755b991183f4323c43 (diff)
Allow registering of OCS routes with the appframework
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AppFramework/Routing/RouteConfig.php55
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..d4b4ec038ad 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']);
+ }
+ }
}
/**