aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Douma <rullzer@users.noreply.github.com>2016-07-19 12:21:14 +0200
committerGitHub <noreply@github.com>2016-07-19 12:21:14 +0200
commit13a25535d2c5c6b181ec31a41f76f825414a26f4 (patch)
treea9a3ae25e8c74823f324b55a66b040a83233a55b /lib
parent544c3c156546d43912808ac18a13eba09f76aa3a (diff)
parentc90a71a83bd97c03e78d33c12976c3fcf515bf44 (diff)
downloadnextcloud-server-13a25535d2c5c6b181ec31a41f76f825414a26f4.tar.gz
nextcloud-server-13a25535d2c5c6b181ec31a41f76f825414a26f4.zip
Merge pull request #400 from nextcloud/ocs_appframework
OCS routes use AppFramework
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/AppFramework/Routing/RouteConfig.php55
-rw-r--r--lib/private/Route/Router.php12
3 files changed, 68 insertions, 1 deletions
diff --git a/lib/base.php b/lib/base.php
index 62ace1bc0ef..be9de93f73f 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -905,7 +905,7 @@ class OC {
* @param OCP\IRequest $request
* @return boolean
*/
- private static function handleLogin(OCP\IRequest $request) {
+ static function handleLogin(OCP\IRequest $request) {
$userSession = self::$server->getUserSession();
if (OC_User::handleApacheAuth()) {
return true;
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']);
+ }
+ }
}
/**
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php
index 01262be390c..f7da827c3db 100644
--- a/lib/private/Route/Router.php
+++ b/lib/private/Route/Router.php
@@ -150,6 +150,11 @@ class Router implements IRouter {
$collection = $this->getCollection($app);
$collection->addPrefix('/apps/' . $app);
$this->root->addCollection($collection);
+
+ // Also add the OCS collection
+ $collection = $this->getCollection($app.'.ocs');
+ $collection->addPrefix('/ocsapp/apps/' . $app);
+ $this->root->addCollection($collection);
}
}
if (!isset($this->loadedApps['core'])) {
@@ -241,6 +246,13 @@ class Router implements IRouter {
$app = \OC_App::cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
+ } else if (substr($url, 0, 13) === '/ocsapp/apps/') {
+ // empty string / 'ocsapp' / 'apps' / $app / rest of the route
+ list(, , , $app,) = explode('/', $url, 5);
+
+ $app = \OC_App::cleanAppId($app);
+ \OC::$REQUESTEDAPP = $app;
+ $this->loadRoutes($app);
} else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
\OC::$REQUESTEDAPP = $url;
if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) {