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 /lib | |
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
Diffstat (limited to 'lib')
-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 |
5 files changed, 176 insertions, 6 deletions
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(); +} |