* 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 \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');
}
}

View File

@ -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() {

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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);
});
}
}

View File

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

View File

@ -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');

View File

@ -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);
}

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();
/**
* 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() {
$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'
];
}
}

View File

@ -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'],