From 9fb759a2f41cf71871a242e4f021faf05951da1b Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 28 Oct 2009 22:38:37 +0100 Subject: [PATCH] Configuration based factories should not require any parameters but the configuration. --- .../Horde/Kolab/Server/Factory/Configuration.php | 15 ++-- .../Kolab/Server/Factory/Conn/Configuration.php | 92 ++++++++++++++++++++++ framework/Kolab_Server/package.xml | 2 + 3 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php index c54ca489e..b031dd9be 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php @@ -44,15 +44,18 @@ implements Horde_Kolab_Server_Factory /** * Constructor. - * - * @param array $config Configuration parameters for the server. */ - public function __construct( - Horde_Kolab_Server_Factory $factory, - array $config - ) { + public function __construct(array $config) + { $this->_configuration = $config; + $connection_factory = new Horde_Kolab_Server_Factory_Conn_Configuration( + $config + ); + $factory = new Horde_Kolab_Server_Factory_Kolab( + $connection_factory, $config + ); + if (isset($config['logger'])) { $factory = new Horde_Kolab_Server_Factory_Logged( $factory, $config['logger'] diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php new file mode 100644 index 000000000..6f4dba1dd --- /dev/null +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php @@ -0,0 +1,92 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ + +/** + * A factory that receives all required details via configuration parameters. + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Server + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Server + */ +class Horde_Kolab_Server_Factory_Conn_Configuration +extends Horde_Kolab_Server_Factory_Conn_Base +{ + /** + * Configuration parameters for the connection. + * + * @var array + */ + private $_configuration; + + /** + * The factory used for creating the instances. + * + * @var Horde_Kolab_Server_Factory + */ + private $_factory; + + /** + * Constructor. + */ + public function __construct(array $config) + { + $this->setConfiguration($config); + } + + /** + * Get the connection configuration. + * + * @return array $configuration The configuration parameters. + */ + public function getConfiguration() + { + return $this->_configuration; + } + + /** + * Set the connection configuration. + * + * @param array $configuration The configuration parameters. + * + * @return NULL + */ + public function setConfiguration(array $configuration) + { + $this->_configuration = $configuration; + + if (empty($configuration['mock'])) { + $this->_factory = new Horde_Kolab_Server_Factory_Conn_Ldap(); + } else { + $this->_factory = new Horde_Kolab_Server_Factory_Conn_Mock(); + } + + $this->_factory->setConfiguration($configuration); + } + + /** + * Return the server connection that should be used. + * + * @return Horde_Kolab_Server_Connection The server connection. + */ + public function getConnection() + { + return $this->_factory->getConnection(); + } +} \ No newline at end of file diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml index efafca52b..0891eea69 100644 --- a/framework/Kolab_Server/package.xml +++ b/framework/Kolab_Server/package.xml @@ -85,6 +85,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -320,6 +321,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + -- 2.11.0