From c80c9819dcc1a4c79b5c2621a3ec07623e1cd140 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Tue, 21 Jul 2015 21:44:59 +0200
Subject: [PATCH] Move core capabilities to new class

---
 lib/private/ocs/cloud.php            |  9 +----
 lib/private/ocs/corecapabilities.php | 56 ++++++++++++++++++++++++++++
 lib/private/server.php               | 11 ++++--
 3 files changed, 65 insertions(+), 11 deletions(-)
 create mode 100644 lib/private/ocs/corecapabilities.php

diff --git a/lib/private/ocs/cloud.php b/lib/private/ocs/cloud.php
index ff6b7977cd9..8f4f1769e9c 100644
--- a/lib/private/ocs/cloud.php
+++ b/lib/private/ocs/cloud.php
@@ -37,14 +37,7 @@ class OC_OCS_Cloud {
 			'edition' => OC_Util::getEditionString(),
 			);
 			
-		$result['capabilities'] = array(
-			'core' => array(
-				'pollinterval' => OC_Config::getValue('pollinterval', 60),
-				),
-		);
-
-
-		$result['capabilities'] = array_merge_recursive($result['capabilities'], \OC::$server->getCapabilitiesManager()->getCapabilities());
+		$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 2c0793f4c1d..5bf3121ec0f 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -59,7 +59,6 @@ use OC\Security\SecureRandom;
 use OC\Security\TrustedDomainHelper;
 use OC\Tagging\TagMapper;
 use OCP\IServerContainer;
-use OC\CapabilitiesManager;
 
 /**
  * Class Server
@@ -450,8 +449,14 @@ class Server extends SimpleContainer implements IServerContainer {
 				$c->getURLGenerator(),
 				\OC::$configDir);
 		});
-		$this->registerService('CapabilitiesManager', function () {
-			return new CapabilitiesManager();
+		$this->registerService('CapabilitiesManager', function (Server $c) {
+			$manager = new \OC\CapabilitiesManager();
+			$manager->registerCapability(function() use ($c) {
+				return new \OC\OCS\CoreCapabilities(
+					$c->getConfig()
+				);
+			});
+			return $manager;
 		});
 	}
 
-- 
GitLab