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_trashbin/appinfo/application.php | 40 +++++++++++++++++++++++++++++ apps/files_trashbin/appinfo/routes.php | 11 ++++---- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 apps/files_trashbin/appinfo/application.php (limited to 'apps/files_trashbin/appinfo') diff --git a/apps/files_trashbin/appinfo/application.php b/apps/files_trashbin/appinfo/application.php new file mode 100644 index 00000000000..851de142e5c --- /dev/null +++ b/apps/files_trashbin/appinfo/application.php @@ -0,0 +1,40 @@ + + * + * @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 OCA\Files_Trashbin\AppInfo; + +use OCP\AppFramework\App; +use OCA\Files_Trashbin\Capabilities; + +class Application extends App { + public function __construct(array $urlParams = array()) { + parent::__construct('files_trashbin', $urlParams); + + $container = $this->getContainer(); + + /* + * Register capabilities + */ + $server->getCapabilitiesManager()->registerCapability(function() { + return new Capabilities(); + }); + } +} diff --git a/apps/files_trashbin/appinfo/routes.php b/apps/files_trashbin/appinfo/routes.php index 99a03d6b969..cf3d7b77ec2 100644 --- a/apps/files_trashbin/appinfo/routes.php +++ b/apps/files_trashbin/appinfo/routes.php @@ -1,9 +1,8 @@ - * @author Joas Schilling * @author Lukas Reschke - * @author Morris Jobke + * @author Roeland Jago Douma * @author Vincent Petry * * @copyright Copyright (c) 2015, ownCloud, Inc. @@ -22,6 +21,11 @@ * along with this program. If not, see * */ + +namespace OCA\Files_Trashbin\AppInfo; + +$application = new Application(); + $this->create('core_ajax_trashbin_preview', 'ajax/preview.php') ->actionInclude('files_trashbin/ajax/preview.php'); $this->create('files_trashbin_ajax_delete', 'ajax/delete.php') @@ -33,6 +37,3 @@ $this->create('files_trashbin_ajax_list', 'ajax/list.php') $this->create('files_trashbin_ajax_undelete', 'ajax/undelete.php') ->actionInclude('files_trashbin/ajax/undelete.php'); - -// Register with the capabilities API -\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files_Trashbin\Capabilities', 'getCapabilities'), 'files_trashbin', \OCP\API::USER_AUTH); -- 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_trashbin/appinfo') 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