From e84cffc063d508f8984909ba3e744eff970ecb88 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 21 Mar 2015 20:12:55 +0100 Subject: Moved core apps to the capabilities manager * Files * Files_Sharing * Files_Trashbin * Files_Versions --- apps/files/appinfo/application.php | 12 +++++++++--- apps/files/appinfo/routes.php | 9 +++------ apps/files/lib/capabilities.php | 37 +++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 23 deletions(-) (limited to 'apps/files') diff --git a/apps/files/appinfo/application.php b/apps/files/appinfo/application.php index c8aaf375d96..f121eb7a401 100644 --- a/apps/files/appinfo/application.php +++ b/apps/files/appinfo/application.php @@ -1,6 +1,5 @@ * @author Roeland Jago Douma * @author Tobias Kaminsky * @author Vincent Petry @@ -21,13 +20,13 @@ * along with this program. If not, see * */ - -namespace OCA\Files\Appinfo; +namespace OCA\Files\AppInfo; use OCA\Files\Controller\ApiController; use OCP\AppFramework\App; use \OCA\Files\Service\TagService; use \OCP\IContainer; +use OCA\Files\Capabilities; class Application extends App { public function __construct(array $urlParams=array()) { @@ -68,5 +67,12 @@ class Application extends App { $homeFolder ); }); + + /* + * Register capabilities + */ + $server->getCapabilitiesManager()->registerCapability(function() { + return new Capabilities(); + }); } } diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 5aa52f17a29..d1b8954d5ce 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -1,9 +1,9 @@ - * @author Joas Schilling * @author Lukas Reschke * @author Morris Jobke + * @author Roeland Jago Douma * @author Tobias Kaminsky * @author Tom Needham * @author Vincent Petry @@ -24,8 +24,7 @@ * along with this program. If not, see * */ - -namespace OCA\Files\Appinfo; +namespace OCA\Files\AppInfo; $application = new Application(); $application->registerRoutes( @@ -82,6 +81,4 @@ $this->create('files_ajax_upload', 'ajax/upload.php') $this->create('download', 'download{file}') ->requirements(array('file' => '.*')) ->actionInclude('files/download.php'); - -// Register with the capabilities API -\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', \OCP\API::USER_AUTH); + diff --git a/apps/files/lib/capabilities.php b/apps/files/lib/capabilities.php index 05d12864dca..2e19283e4d6 100644 --- a/apps/files/lib/capabilities.php +++ b/apps/files/lib/capabilities.php @@ -1,7 +1,7 @@ - * @author Morris Jobke + * @author Roeland Jago Douma * @author Tom Needham * * @copyright Copyright (c) 2015, ownCloud, Inc. @@ -20,19 +20,28 @@ * along with this program. If not, see * */ - -namespace OCA\Files; -class Capabilities { - - public static function getCapabilities() { - return new \OC_OCS_Result(array( - 'capabilities' => array( - 'files' => array( - 'bigfilechunking' => true, - ), - ), - )); +namespace OCA\Files; + +use OCP\Capabilities\ICapability; + +/** + * Class Capabilities + * + * @package OCA\Files + */ +class Capabilities implements ICapability { + + /** + * Return this classes capabilities + * + * @return array + */ + public function getCapabilities() { + return [ + 'files' => [ + 'bigfilechunking' => true, + ], + ]; } - } -- cgit v1.2.3 From f0b617b50825566ec1b417eed09688e88de5f0bb Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 22 Jul 2015 13:04:56 +0200 Subject: Use DI * Register OCP\Capability\IManager at DIContainer * Add register capabilities to appframework * Register capabilities in DI way * Make unit test pass again * Remove CapabiltiesManager from OCP --- apps/files/appinfo/application.php | 5 +-- apps/files_sharing/appinfo/application.php | 6 +-- apps/files_trashbin/appinfo/application.php | 5 +-- apps/files_versions/appinfo/application.php | 5 +-- .../dependencyinjection/dicontainer.php | 14 +++++++ lib/private/capabilitiesmanager.php | 3 +- lib/private/server.php | 8 ++-- lib/public/appframework/iappcontainer.php | 7 ++++ lib/public/capabilities/imanager.php | 44 ---------------------- lib/public/iservercontainer.php | 7 ---- tests/lib/capabilitiesmanager.php | 31 +++++++-------- tests/lib/server.php | 2 +- 12 files changed, 44 insertions(+), 93 deletions(-) delete mode 100644 lib/public/capabilities/imanager.php (limited to 'apps/files') diff --git a/apps/files/appinfo/application.php b/apps/files/appinfo/application.php index f121eb7a401..6ba77e09556 100644 --- a/apps/files/appinfo/application.php +++ b/apps/files/appinfo/application.php @@ -26,7 +26,6 @@ use OCA\Files\Controller\ApiController; use OCP\AppFramework\App; use \OCA\Files\Service\TagService; use \OCP\IContainer; -use OCA\Files\Capabilities; class Application extends App { public function __construct(array $urlParams=array()) { @@ -71,8 +70,6 @@ class Application extends App { /* * Register capabilities */ - $server->getCapabilitiesManager()->registerCapability(function() { - return new Capabilities(); - }); + $container->registerCapability('OCA\Files\Capabilities'); } } diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php index 6ddd25acb52..2fe9019d54e 100644 --- a/apps/files_sharing/appinfo/application.php +++ b/apps/files_sharing/appinfo/application.php @@ -128,11 +128,7 @@ class Application extends App { /* * Register capabilities */ - $server->getCapabilitiesManager()->registerCapability(function() use ($server) { - return new Capabilities( - $server->getConfig() - ); - }); + $container->registerCapability('OCA\Files_Sharing\Capabilities'); } public function registerMountProviders() { diff --git a/apps/files_trashbin/appinfo/application.php b/apps/files_trashbin/appinfo/application.php index 851de142e5c..8d76d40f639 100644 --- a/apps/files_trashbin/appinfo/application.php +++ b/apps/files_trashbin/appinfo/application.php @@ -22,7 +22,6 @@ namespace OCA\Files_Trashbin\AppInfo; use OCP\AppFramework\App; -use OCA\Files_Trashbin\Capabilities; class Application extends App { public function __construct(array $urlParams = array()) { @@ -33,8 +32,6 @@ class Application extends App { /* * Register capabilities */ - $server->getCapabilitiesManager()->registerCapability(function() { - return new Capabilities(); - }); + $container->registerCapability('OCA\Files_Trashbin\Capabilities'); } } diff --git a/apps/files_versions/appinfo/application.php b/apps/files_versions/appinfo/application.php index 69485bc1f22..bab36b48510 100644 --- a/apps/files_versions/appinfo/application.php +++ b/apps/files_versions/appinfo/application.php @@ -22,7 +22,6 @@ namespace OCA\Files_Versions\AppInfo; use OCP\AppFramework\App; -use OCA\Files_Versions\Capabilities; class Application extends App { public function __construct(array $urlParams = array()) { @@ -33,8 +32,6 @@ class Application extends App { /* * Register capabilities */ - $server->getCapabilitiesManager()->registerCapability(function() { - return new Capabilities(); - }); + $container->registerCapability('OCA\Files_Versions\Capabilities'); } } 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 index ebbd9664897..74154f2c631 100644 --- a/lib/private/capabilitiesmanager.php +++ b/lib/private/capabilitiesmanager.php @@ -21,10 +21,9 @@ namespace OC; -use OCP\Capabilities\IManager; use OCP\Capabilities\ICapability; -class CapabilitiesManager implements IManager { +class CapabilitiesManager { /** * @var \Closure[] diff --git a/lib/private/server.php b/lib/private/server.php index 5bf3121ec0f..9503cf16ff7 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -452,12 +452,11 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('CapabilitiesManager', function (Server $c) { $manager = new \OC\CapabilitiesManager(); $manager->registerCapability(function() use ($c) { - return new \OC\OCS\CoreCapabilities( - $c->getConfig() - ); + return new \OC\OCS\CoreCapabilities($c->getConfig()); }); return $manager; }); + } /** @@ -958,8 +957,7 @@ class Server extends SimpleContainer implements IServerContainer { /** * Get the manager of all the capabilities * - * @return \OCP\Capabilities\IManager - * @since 8.2.0 + * @return \OC\CapabilitiesManager */ public function getCapabilitiesManager() { return $this->query('CapabilitiesManager'); diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index 64b1082aa97..7338dbd858d 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -86,4 +86,11 @@ interface IAppContainer extends IContainer { */ function log($message, $level); + /** + * Register a capability + * + * @param string $serviceName e.g. 'OCA\Files\Capabilities' + * @since 8.2.0 + */ + public function registerCapability($serviceName); } diff --git a/lib/public/capabilities/imanager.php b/lib/public/capabilities/imanager.php deleted file mode 100644 index df563bd2b25..00000000000 --- a/lib/public/capabilities/imanager.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * @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 - * - */ -namespace OCP\Capabilities; - - -interface IManager { - - /** - * Get an array of al the capabilities that are registered at this manager - * - * @return array All the capabilities registered in this manager - * @since 8.2.0 - */ - public function getCapabilities(); - - /** - * In order to improve lazy loading a closure can be registered which will be called in case - * activity consumers are actually requested - * - * $callable has to return an instance of OCP\Capabilities\ICapability - * - * @param \Closure $callable - * @since 8.2.0 - */ - public function registerCapability(\Closure $callable); -} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 6cb8d668658..ab1729da255 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -439,11 +439,4 @@ interface IServerContainer { */ public function getMimeTypeDetector(); - /** - * Get the manager of all the capabilities - * - * @return \OCP\Capabilities\IManager - * @since 8.2.0 - */ - public function getCapabilitiesManager(); } diff --git a/tests/lib/capabilitiesmanager.php b/tests/lib/capabilitiesmanager.php index 738715344e0..b5dac80ee51 100644 --- a/tests/lib/capabilitiesmanager.php +++ b/tests/lib/capabilitiesmanager.php @@ -70,18 +70,14 @@ class CapabilitiesManagerTest extends TestCase { public function testMergedCapabilities() { $manager = new \OC\CapabilitiesManager(); - $simple1 = new SimpleCapability(); - $simple2 = new SimpleCapability2(); - $simple3 = new SimpleCapability3(); - - $manager->registerCapability(function() use ($simple1) { - return $simple1; + $manager->registerCapability(function() { + return new SimpleCapability(); }); - $manager->registerCapability(function() use ($simple2) { - return $simple2; + $manager->registerCapability(function() { + return new SimpleCapability2(); }); - $manager->registerCapability(function() use ($simple3) { - return $simple3; + $manager->registerCapability(function() { + return new SimpleCapability3(); }); $res = $manager->getCapabilities(); @@ -146,6 +142,14 @@ class SimpleCapability3 implements \OCP\Capabilities\ICapability { } } +class NoCapability { + public function getCapabilities() { + return [ + 'baz' => 'z' + ]; + } +} + class DeepCapability implements \OCP\Capabilities\ICapability { public function getCapabilities() { return [ @@ -158,10 +162,3 @@ class DeepCapability implements \OCP\Capabilities\ICapability { } } -class NoCapability { - public function getCapabilities() { - return [ - 'baz' => 'z' - ]; - } -} diff --git a/tests/lib/server.php b/tests/lib/server.php index 1eb91173deb..9c5c83ceb5c 100644 --- a/tests/lib/server.php +++ b/tests/lib/server.php @@ -51,7 +51,7 @@ class Server extends \Test\TestCase { ['AvatarManager', '\OC\AvatarManager'], ['AvatarManager', '\OCP\IAvatarManager'], - ['CapabilitiesManager', '\OCP\Capabilities\IManager'], + ['CapabilitiesManager', '\OC\CapabilitiesManager'], ['ContactsManager', '\OC\ContactsManager'], ['ContactsManager', '\OCP\Contacts\IManager'], ['Crypto', '\OC\Security\Crypto'], -- cgit v1.2.3