* 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
This commit is contained in:
Roeland Jago Douma 2015-07-22 13:04:56 +02:00
parent c80c9819dc
commit f0b617b508
12 changed files with 44 additions and 93 deletions

View File

@ -26,7 +26,6 @@ use OCA\Files\Controller\ApiController;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use \OCA\Files\Service\TagService; use \OCA\Files\Service\TagService;
use \OCP\IContainer; use \OCP\IContainer;
use OCA\Files\Capabilities;
class Application extends App { class Application extends App {
public function __construct(array $urlParams=array()) { public function __construct(array $urlParams=array()) {
@ -71,8 +70,6 @@ class Application extends App {
/* /*
* Register capabilities * Register capabilities
*/ */
$server->getCapabilitiesManager()->registerCapability(function() { $container->registerCapability('OCA\Files\Capabilities');
return new Capabilities();
});
} }
} }

View File

@ -128,11 +128,7 @@ class Application extends App {
/* /*
* Register capabilities * Register capabilities
*/ */
$server->getCapabilitiesManager()->registerCapability(function() use ($server) { $container->registerCapability('OCA\Files_Sharing\Capabilities');
return new Capabilities(
$server->getConfig()
);
});
} }
public function registerMountProviders() { public function registerMountProviders() {

View File

@ -22,7 +22,6 @@
namespace OCA\Files_Trashbin\AppInfo; namespace OCA\Files_Trashbin\AppInfo;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCA\Files_Trashbin\Capabilities;
class Application extends App { class Application extends App {
public function __construct(array $urlParams = array()) { public function __construct(array $urlParams = array()) {
@ -33,8 +32,6 @@ class Application extends App {
/* /*
* Register capabilities * Register capabilities
*/ */
$server->getCapabilitiesManager()->registerCapability(function() { $container->registerCapability('OCA\Files_Trashbin\Capabilities');
return new Capabilities();
});
} }
} }

View File

@ -22,7 +22,6 @@
namespace OCA\Files_Versions\AppInfo; namespace OCA\Files_Versions\AppInfo;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCA\Files_Versions\Capabilities;
class Application extends App { class Application extends App {
public function __construct(array $urlParams = array()) { public function __construct(array $urlParams = array()) {
@ -33,8 +32,6 @@ class Application extends App {
/* /*
* Register capabilities * Register capabilities
*/ */
$server->getCapabilitiesManager()->registerCapability(function() { $container->registerCapability('OCA\Files_Versions\Capabilities');
return new Capabilities();
});
} }
} }

View File

@ -96,6 +96,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getMemCacheFactory(); return $this->getServer()->getMemCacheFactory();
}); });
$this->registerService('OC\\CapabilitiesManager', function($c) {
return $this->getServer()->getCapabilitiesManager();
});
$this->registerService('OCP\\IConfig', function($c) { $this->registerService('OCP\\IConfig', function($c) {
return $this->getServer()->getConfig(); return $this->getServer()->getConfig();
}); });
@ -390,5 +394,15 @@ class DIContainer extends SimpleContainer implements IAppContainer {
\OCP\Util::writeLog($this->getAppName(), $message, $level); \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);
});
}
} }

View File

@ -21,10 +21,9 @@
namespace OC; namespace OC;
use OCP\Capabilities\IManager;
use OCP\Capabilities\ICapability; use OCP\Capabilities\ICapability;
class CapabilitiesManager implements IManager { class CapabilitiesManager {
/** /**
* @var \Closure[] * @var \Closure[]

View File

@ -452,12 +452,11 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('CapabilitiesManager', function (Server $c) { $this->registerService('CapabilitiesManager', function (Server $c) {
$manager = new \OC\CapabilitiesManager(); $manager = new \OC\CapabilitiesManager();
$manager->registerCapability(function() use ($c) { $manager->registerCapability(function() use ($c) {
return new \OC\OCS\CoreCapabilities( return new \OC\OCS\CoreCapabilities($c->getConfig());
$c->getConfig()
);
}); });
return $manager; return $manager;
}); });
} }
/** /**
@ -958,8 +957,7 @@ class Server extends SimpleContainer implements IServerContainer {
/** /**
* Get the manager of all the capabilities * Get the manager of all the capabilities
* *
* @return \OCP\Capabilities\IManager * @return \OC\CapabilitiesManager
* @since 8.2.0
*/ */
public function getCapabilitiesManager() { public function getCapabilitiesManager() {
return $this->query('CapabilitiesManager'); return $this->query('CapabilitiesManager');

View File

@ -86,4 +86,11 @@ interface IAppContainer extends IContainer {
*/ */
function log($message, $level); function log($message, $level);
/**
* Register a capability
*
* @param string $serviceName e.g. 'OCA\Files\Capabilities'
* @since 8.2.0
*/
public function registerCapability($serviceName);
} }

View File

@ -1,44 +0,0 @@
<?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 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);
}

View File

@ -439,11 +439,4 @@ interface IServerContainer {
*/ */
public function getMimeTypeDetector(); public function getMimeTypeDetector();
/**
* Get the manager of all the capabilities
*
* @return \OCP\Capabilities\IManager
* @since 8.2.0
*/
public function getCapabilitiesManager();
} }

View File

@ -70,18 +70,14 @@ class CapabilitiesManagerTest extends TestCase {
public function testMergedCapabilities() { public function testMergedCapabilities() {
$manager = new \OC\CapabilitiesManager(); $manager = new \OC\CapabilitiesManager();
$simple1 = new SimpleCapability(); $manager->registerCapability(function() {
$simple2 = new SimpleCapability2(); return new SimpleCapability();
$simple3 = new SimpleCapability3();
$manager->registerCapability(function() use ($simple1) {
return $simple1;
}); });
$manager->registerCapability(function() use ($simple2) { $manager->registerCapability(function() {
return $simple2; return new SimpleCapability2();
}); });
$manager->registerCapability(function() use ($simple3) { $manager->registerCapability(function() {
return $simple3; return new SimpleCapability3();
}); });
$res = $manager->getCapabilities(); $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 { class DeepCapability implements \OCP\Capabilities\ICapability {
public function getCapabilities() { public function getCapabilities() {
return [ return [
@ -158,10 +162,3 @@ class DeepCapability implements \OCP\Capabilities\ICapability {
} }
} }
class NoCapability {
public function getCapabilities() {
return [
'baz' => 'z'
];
}
}

View File

@ -51,7 +51,7 @@ class Server extends \Test\TestCase {
['AvatarManager', '\OC\AvatarManager'], ['AvatarManager', '\OC\AvatarManager'],
['AvatarManager', '\OCP\IAvatarManager'], ['AvatarManager', '\OCP\IAvatarManager'],
['CapabilitiesManager', '\OCP\Capabilities\IManager'], ['CapabilitiesManager', '\OC\CapabilitiesManager'],
['ContactsManager', '\OC\ContactsManager'], ['ContactsManager', '\OC\ContactsManager'],
['ContactsManager', '\OCP\Contacts\IManager'], ['ContactsManager', '\OCP\Contacts\IManager'],
['Crypto', '\OC\Security\Crypto'], ['Crypto', '\OC\Security\Crypto'],