summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-21 12:13:01 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-21 12:13:01 +0100
commit7c7467fe4244cb26a86670bc89194da7b4dc82b5 (patch)
tree4b4d203386cc9780398e654cafff73c8ab70e938 /lib
parentec8022d241541b25a0e4d01857bf6a0c1ed74eca (diff)
parent899f9bd113304d77b865653768450f6013824553 (diff)
downloadnextcloud-server-7c7467fe4244cb26a86670bc89194da7b4dc82b5.tar.gz
nextcloud-server-7c7467fe4244cb26a86670bc89194da7b4dc82b5.zip
Merge pull request #21792 from owncloud/systemtags-managerfactory
Allow custom implementation of system tag managers
Diffstat (limited to 'lib')
-rw-r--r--lib/private/comments/managerfactory.php22
-rw-r--r--lib/private/server.php13
-rw-r--r--lib/private/systemtag/managerfactory.php78
-rw-r--r--lib/public/comments/icommentsmanagerfactory.php10
-rw-r--r--lib/public/systemtag/isystemtagmanagerfactory.php59
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 db36fbc1433..a16e6b9839b 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
@@ -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() {
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();
+}