summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Douma <rullzer@users.noreply.github.com>2015-08-10 20:33:50 +0200
committerRoeland Douma <rullzer@users.noreply.github.com>2015-08-10 20:33:50 +0200
commitc2856c05aa9cbdc3adddea127a8588183647ee0a (patch)
treead9f474fb95007345f2e78c3d4e998d0f6f97308 /lib/private
parent6e4a79f8529a69b846f73257cc581d2b80f7762d (diff)
parentf0b617b50825566ec1b417eed09688e88de5f0bb (diff)
downloadnextcloud-server-c2856c05aa9cbdc3adddea127a8588183647ee0a.tar.gz
nextcloud-server-c2856c05aa9cbdc3adddea127a8588183647ee0a.zip
Merge pull request #15093 from rullzer/capabilities_manager
Capabilities manager
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/appframework/dependencyinjection/dicontainer.php14
-rw-r--r--lib/private/capabilitiesmanager.php64
-rw-r--r--lib/private/ocs/cloud.php9
-rw-r--r--lib/private/ocs/corecapabilities.php56
-rw-r--r--lib/private/server.php17
5 files changed, 154 insertions, 6 deletions
diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php
index 927b6d43302..c66b792064d 100644
--- a/lib/private/appframework/dependencyinjection/dicontainer.php
+++ b/lib/private/appframework/dependencyinjection/dicontainer.php
@@ -96,6 +96,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getMemCacheFactory();
});
+ $this->registerService('OC\\CapabilitiesManager', function($c) {
+ return $this->getServer()->getCapabilitiesManager();
+ });
+
$this->registerService('OCP\\IConfig', function($c) {
return $this->getServer()->getConfig();
});
@@ -390,5 +394,15 @@ class DIContainer extends SimpleContainer implements IAppContainer {
\OCP\Util::writeLog($this->getAppName(), $message, $level);
}
+ /**
+ * Register a capability
+ *
+ * @param string $serviceName e.g. 'OCA\Files\Capabilities'
+ */
+ public function registerCapability($serviceName) {
+ $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
+ return $this->query($serviceName);
+ });
+ }
}
diff --git a/lib/private/capabilitiesmanager.php b/lib/private/capabilitiesmanager.php
new file mode 100644
index 00000000000..74154f2c631
--- /dev/null
+++ b/lib/private/capabilitiesmanager.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OC;
+
+
+use OCP\Capabilities\ICapability;
+
+class CapabilitiesManager {
+
+ /**
+ * @var \Closure[]
+ */
+ private $capabilities = array();
+
+ /**
+ * Get an array of al the capabilities that are registered at this manager
+ *
+ * @throws \InvalidArgumentException
+ * @return array
+ */
+ public function getCapabilities() {
+ $capabilities = [];
+ foreach($this->capabilities as $capability) {
+ $c = $capability();
+ if ($c instanceof ICapability) {
+ $capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
+ } else {
+ throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface');
+ }
+ }
+
+ return $capabilities;
+ }
+
+ /**
+ * In order to improve lazy loading a closure can be registered which will be called in case
+ * capabilities are actually requested
+ *
+ * $callable has to return an instance of OCP\Capabilities\ICapability
+ *
+ * @param \Closure $callable
+ */
+ public function registerCapability(\Closure $callable) {
+ array_push($this->capabilities, $callable);
+ }
+}
diff --git a/lib/private/ocs/cloud.php b/lib/private/ocs/cloud.php
index f662bde2858..8f4f1769e9c 100644
--- a/lib/private/ocs/cloud.php
+++ b/lib/private/ocs/cloud.php
@@ -3,6 +3,7 @@
* @author Bart Visscher <bartv@thisnet.nl>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Tom Needham <tom@owncloud.com>
*
@@ -36,12 +37,8 @@ class OC_OCS_Cloud {
'edition' => OC_Util::getEditionString(),
);
- $result['capabilities'] = array(
- 'core' => array(
- 'pollinterval' => OC_Config::getValue('pollinterval', 60),
- ),
- );
-
+ $result['capabilities'] = \OC::$server->getCapabilitiesManager()->getCapabilities();
+
return new OC_OCS_Result($result);
}
diff --git a/lib/private/ocs/corecapabilities.php b/lib/private/ocs/corecapabilities.php
new file mode 100644
index 00000000000..6b620ab0a84
--- /dev/null
+++ b/lib/private/ocs/corecapabilities.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\OCS;
+
+use OCP\Capabilities\ICapability;
+use OCP\IConfig;
+
+/**
+ * Class Capabilities
+ *
+ * @package OC\OCS
+ */
+class CoreCapabilities implements ICapability {
+
+ /** @var IConfig */
+ private $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
+ /**
+ * Return this classes capabilities
+ *
+ * @return array
+ */
+ public function getCapabilities() {
+ return [
+ 'core' => [
+ 'pollinterval' => $this->config->getSystemValue('pollinterval', 60)
+ ]
+ ];
+ }
+}
diff --git a/lib/private/server.php b/lib/private/server.php
index 12981fe7f19..9503cf16ff7 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -449,6 +449,14 @@ class Server extends SimpleContainer implements IServerContainer {
$c->getURLGenerator(),
\OC::$configDir);
});
+ $this->registerService('CapabilitiesManager', function (Server $c) {
+ $manager = new \OC\CapabilitiesManager();
+ $manager->registerCapability(function() use ($c) {
+ return new \OC\OCS\CoreCapabilities($c->getConfig());
+ });
+ return $manager;
+ });
+
}
/**
@@ -945,4 +953,13 @@ class Server extends SimpleContainer implements IServerContainer {
public function getMimeTypeDetector() {
return $this->query('MimeTypeDetector');
}
+
+ /**
+ * Get the manager of all the capabilities
+ *
+ * @return \OC\CapabilitiesManager
+ */
+ public function getCapabilitiesManager() {
+ return $this->query('CapabilitiesManager');
+ }
}