diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-01-19 16:17:49 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-01-20 16:36:10 +0100 |
commit | 899f9bd113304d77b865653768450f6013824553 (patch) | |
tree | 9861ca8e2d64e9dc373a330f7342b424172cbeb1 | |
parent | dd733d89256e0a2d1f7f4f96ac46b5a7bfbff984 (diff) | |
download | nextcloud-server-899f9bd113304d77b865653768450f6013824553.tar.gz nextcloud-server-899f9bd113304d77b865653768450f6013824553.zip |
Allow custom implementation of system tag managers
Added config.php option to replace the default implementation of system
tag manager and system tag object mapper.
Also adjusted the comments manager factory to inject the server container
-rw-r--r-- | config/config.sample.php | 7 | ||||
-rw-r--r-- | lib/private/comments/managerfactory.php | 22 | ||||
-rw-r--r-- | lib/private/server.php | 13 | ||||
-rw-r--r-- | lib/private/systemtag/managerfactory.php | 78 | ||||
-rw-r--r-- | lib/public/comments/icommentsmanagerfactory.php | 10 | ||||
-rw-r--r-- | lib/public/systemtag/isystemtagmanagerfactory.php | 59 | ||||
-rw-r--r-- | tests/lib/comments/fakefactory.php | 5 | ||||
-rw-r--r-- | tests/lib/comments/manager.php | 2 | ||||
-rw-r--r-- | tests/lib/server.php | 3 |
9 files changed, 192 insertions, 7 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index 3dc1f4818c0..3f6ae4bc3ec 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -819,6 +819,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 * * These options are for halting user activity when you are performing server diff --git a/lib/private/comments/managerfactory.php b/lib/private/comments/managerfactory.php index c2a2e0b4891..281e8ca7fef 100644 --- a/lib/private/comments/managerfactory.php +++ b/lib/private/comments/managerfactory.php @@ -22,11 +22,27 @@ 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 * * @return 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() ); } } diff --git a/lib/private/server.php b/lib/private/server.php index 642267e8568..006faf6a717 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -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 @@ -533,7 +540,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() { diff --git a/lib/private/systemtag/managerfactory.php b/lib/private/systemtag/managerfactory.php new file mode 100644 index 00000000000..7b7b9558b04 --- /dev/null +++ b/lib/private/systemtag/managerfactory.php @@ -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() + ); + } +} diff --git a/lib/public/comments/icommentsmanagerfactory.php b/lib/public/comments/icommentsmanagerfactory.php index 03a2b16b310..2e71719019c 100644 --- a/lib/public/comments/icommentsmanagerfactory.php +++ b/lib/public/comments/icommentsmanagerfactory.php @@ -20,6 +20,8 @@ */ namespace OCP\Comments; +use OCP\IServerContainer; + /** * Interface ICommentsManagerFactory * @@ -32,6 +34,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 * * @return ICommentsManager diff --git a/lib/public/systemtag/isystemtagmanagerfactory.php b/lib/public/systemtag/isystemtagmanagerfactory.php new file mode 100644 index 00000000000..ad7467633b1 --- /dev/null +++ b/lib/public/systemtag/isystemtagmanagerfactory.php @@ -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(); +} diff --git a/tests/lib/comments/fakefactory.php b/tests/lib/comments/fakefactory.php index 837bcb10585..ff8dfd3a259 100644 --- a/tests/lib/comments/fakefactory.php +++ b/tests/lib/comments/fakefactory.php @@ -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(); } diff --git a/tests/lib/comments/manager.php b/tests/lib/comments/manager.php index 248de683253..cc2eebb64d1 100644 --- a/tests/lib/comments/manager.php +++ b/tests/lib/comments/manager.php @@ -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(); } diff --git a/tests/lib/server.php b/tests/lib/server.php index 44e1aac5cce..684e6a97361 100644 --- a/tests/lib/server.php +++ b/tests/lib/server.php @@ -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'], ]; } |