Merge pull request #21792 from owncloud/systemtags-managerfactory

Allow custom implementation of system tag managers
This commit is contained in:
Thomas Müller 2016-01-21 12:13:01 +01:00
commit 7c7467fe42
9 changed files with 192 additions and 7 deletions

View File

@ -818,6 +818,13 @@ $CONFIG = array(
*/
'comments.managerFactory' => '\OC\Comments\ManagerFactory',
/**
* Replaces the default System Tags Manager Factory. This can be utilized if an
* own or 3rdParty SystemTagsManager should be used that for instance uses the
* filesystem instead of the database to keep the comments.
*/
'systemtags.managerFactory' => '\OC\SystemTag\ManagerFactory',
/**
* Maintenance
*

View File

@ -22,10 +22,26 @@ namespace OC\Comments;
use OCP\Comments\ICommentsManager;
use OCP\Comments\ICommentsManagerFactory;
use OCP\IServerContainer;
class ManagerFactory implements ICommentsManagerFactory {
/**
* Server container
*
* @var IServerContainer
*/
private $serverContainer;
/**
* Constructor for the comments manager factory
*
* @param IServerContainer $serverContainer server container
*/
public function __construct(IServerContainer $serverContainer) {
$this->serverContainer = $serverContainer;
}
/**
* creates and returns an instance of the ICommentsManager
*
@ -34,8 +50,8 @@ class ManagerFactory implements ICommentsManagerFactory {
*/
public function getManager() {
return new Manager(
\OC::$server->getDatabaseConnection(),
\OC::$server->getLogger()
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getLogger()
);
}
}

View File

@ -143,11 +143,18 @@ class Server extends ServerContainer implements IServerContainer {
$tagMapper = $c->query('TagMapper');
return new TagManager($tagMapper, $c->getUserSession());
});
$this->registerService('SystemTagManagerFactory', function (Server $c) {
$config = $c->getConfig();
$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
/** @var \OC\SystemTag\ManagerFactory $factory */
$factory = new $factoryClass($this);
return $factory;
});
$this->registerService('SystemTagManager', function (Server $c) {
return new SystemTag\SystemTagManager($c->getDatabaseConnection());
return $c->query('SystemTagManagerFactory')->getManager();
});
$this->registerService('SystemTagObjectMapper', function (Server $c) {
return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager());
return $c->query('SystemTagManagerFactory')->getObjectMapper();
});
$this->registerService('RootFolder', function (Server $c) {
// TODO: get user and user manager from container as well
@ -537,7 +544,7 @@ class Server extends ServerContainer implements IServerContainer {
$config = $c->getConfig();
$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
/** @var \OCP\Comments\ICommentsManagerFactory $factory */
$factory = new $factoryClass();
$factory = new $factoryClass($this);
return $factory->getManager();
});
$this->registerService('EventDispatcher', function() {

View File

@ -0,0 +1,78 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, 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\SystemTag;
use OCP\SystemTag\ISystemTagManagerFactory;
use OCP\SystemTag\ISystemTagManager;
use OC\SystemTag\SystemTagManager;
use OC\SystemTag\SystemTagObjectMapper;
use OCP\IServerContainer;
/**
* Default factory class for system tag managers
*
* @package OCP\SystemTag
* @since 9.0.0
*/
class ManagerFactory implements ISystemTagManagerFactory {
/**
* Server container
*
* @var IServerContainer
*/
private $serverContainer;
/**
* Constructor for the system tag manager factory
*
* @param IServerContainer $serverContainer server container
*/
public function __construct(IServerContainer $serverContainer) {
$this->serverContainer = $serverContainer;
}
/**
* Creates and returns an instance of the system tag manager
*
* @return ISystemTagManager
* @since 9.0.0
*/
public function getManager() {
return new SystemTagManager(
$this->serverContainer->getDatabaseConnection()
);
}
/**
* Creates and returns an instance of the system tag object
* mapper
*
* @return ISystemTagObjectMapper
* @since 9.0.0
*/
public function getObjectMapper() {
return new SystemTagObjectMapper(
$this->serverContainer->getDatabaseConnection(),
$this->getManager()
);
}
}

View File

@ -20,6 +20,8 @@
*/
namespace OCP\Comments;
use OCP\IServerContainer;
/**
* Interface ICommentsManagerFactory
*
@ -31,6 +33,14 @@ namespace OCP\Comments;
*/
interface ICommentsManagerFactory {
/**
* Constructor for the comments manager factory
*
* @param IServerContainer $serverContainer server container
* @since 9.0.0
*/
public function __construct(IServerContainer $serverContainer);
/**
* creates and returns an instance of the ICommentsManager
*

View File

@ -0,0 +1,59 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, 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\SystemTag;
use OCP\IServerContainer;
/**
* Interface ISystemTagManagerFactory
*
* Factory interface for system tag managers
*
* @package OCP\SystemTag
* @since 9.0.0
*/
interface ISystemTagManagerFactory {
/**
* Constructor for the system tag manager factory
*
* @param IServerContainer $serverContainer server container
* @since 9.0.0
*/
public function __construct(IServerContainer $serverContainer);
/**
* creates and returns an instance of the system tag manager
*
* @return ISystemTagManager
* @since 9.0.0
*/
public function getManager();
/**
* creates and returns an instance of the system tag object
* mapper
*
* @return ISystemTagObjectMapper
* @since 9.0.0
*/
public function getObjectMapper();
}

View File

@ -2,11 +2,16 @@
namespace Test\Comments;
use OCP\IServerContainer;
/**
* Class FakeFactory
*/
class FakeFactory implements \OCP\Comments\ICommentsManagerFactory {
public function __construct(IServerContainer $serverContainer) {
}
public function getManager() {
return new FakeManager();
}

View File

@ -50,7 +50,7 @@ class Test_Comments_Manager extends TestCase
}
protected function getManager() {
$factory = new \OC\Comments\ManagerFactory();
$factory = new \OC\Comments\ManagerFactory(\OC::$server);
return $factory->getManager();
}

View File

@ -155,6 +155,9 @@ class Server extends \Test\TestCase {
['TempManager', '\OC\TempManager'],
['TempManager', '\OCP\ITempManager'],
['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'],
['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'],
['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'],
];
}