summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-01-21 12:02:36 +0100
committerJoas Schilling <coding@schilljs.com>2019-01-22 14:18:58 +0100
commitf8b74cf0a5c62f062d6f05add8e69874e7edc8aa (patch)
treecbbf923f6ef112eb6cf4998b6543204d805bfd9a /lib
parentf8275a7c98fe10572d56e5bca5b2b0ad98f36dcf (diff)
downloadnextcloud-server-f8b74cf0a5c62f062d6f05add8e69874e7edc8aa.tar.gz
nextcloud-server-f8b74cf0a5c62f062d6f05add8e69874e7edc8aa.zip
Allow resources via OCS as well
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AppFramework/Routing/RouteConfig.php56
1 files changed, 55 insertions, 1 deletions
diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php
index 70208725f46..30cd4cea167 100644
--- a/lib/private/AppFramework/Routing/RouteConfig.php
+++ b/lib/private/AppFramework/Routing/RouteConfig.php
@@ -84,6 +84,9 @@ class RouteConfig {
// parse ocs simple routes
$this->processOCS($this->routes);
+ // parse ocs simple routes
+ $this->processOCSResources($this->routes);
+
$this->router->useCollection($oldCollection);
}
@@ -190,7 +193,58 @@ class RouteConfig {
* For a given name and url restful routes are created:
* - index
* - show
- * - new
+ * - create
+ * - update
+ * - destroy
+ *
+ * @param array $routes
+ */
+ private function processOCSResources($routes)
+ {
+ // declaration of all restful actions
+ $actions = array(
+ array('name' => 'index', 'verb' => 'GET', 'on-collection' => true),
+ array('name' => 'show', 'verb' => 'GET'),
+ array('name' => 'create', 'verb' => 'POST', 'on-collection' => true),
+ array('name' => 'update', 'verb' => 'PUT'),
+ array('name' => 'destroy', 'verb' => 'DELETE'),
+ );
+
+ $resources = $routes['ocs-resources'] ?? [];
+ foreach ($resources as $resource => $config) {
+ $root = $config['root'] ?? '/apps/' . $this->appName;
+
+ // the url parameter used as id to the resource
+ foreach($actions as $action) {
+ $url = $root . $config['url'];
+ $method = $action['name'];
+ $verb = strtoupper($action['verb'] ?? 'GET');
+ $collectionAction = $action['on-collection'] ?? false;
+ if (!$collectionAction) {
+ $url .= '/{id}';
+ }
+ if (isset($action['url-postfix'])) {
+ $url .= '/' . $action['url-postfix'];
+ }
+
+ $controller = $resource;
+
+ $controllerName = $this->buildControllerName($controller);
+ $actionName = $this->buildActionName($method);
+
+ $routeName = 'ocs.' . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method);
+
+ $this->router->create($routeName, $url)->method($verb)->action(
+ new RouteActionHandler($this->container, $controllerName, $actionName)
+ );
+ }
+ }
+ }
+
+ /**
+ * For a given name and url restful routes are created:
+ * - index
+ * - show
* - create
* - update
* - destroy