1
0
Fork 0

Implemented new Configuration handling

Dieser Commit ist enthalten in:
DSB 2012-08-04 10:40:48 +00:00
Ursprung 6cfb97b401
Commit edc44e2f30
22 geänderte Dateien mit 730 neuen und 107 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,67 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Config
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Class for dynamic (session lifetime) configuration settings.
*
* @package MySQLDumper
* @subpackage Config
*/
class Msd_Config_Dynamic
{
/**
* Instance of Zend_Session_Namespace for session storage.
*
* @var Zend_Session_Namespace
*/
private $_namespace = null;
/**
* Class constructor.
*
* @param string $sessionNsName Name of the session namespace.
*
* @return Msd_Config_Dynamic
*/
public function __construct($sessionNsName = 'Dynamic')
{
$this->_namespace = new Zend_Session_Namespace($sessionNsName);
}
/**
* Retrieves the value of a parameter.
*
* @param string $name Name of the parameter.
* @param mixed $default Default value to return, if param isn't set.
*
* @return mixed
*/
public function getParam($name, $default = null)
{
if (isset($this->_namespace->$name)) {
return $this->_namespace->$name;
}
return $default;
}
/**
* Sets a value for the given parameter.
*
* @param string $name Name of the parameter.
* @param mixed $value Value for the parameter.
*
* @return void
*/
public function setParam($name, $value)
{
$this->_namespace->$name = $value;
}
}

Datei anzeigen

@ -0,0 +1,19 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Config
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Exception class for configuration class.
*
* @package MySQLDumper
* @subpackage Config
*/
class Msd_Config_Exception extends Msd_Exception
{
}

Datei anzeigen

@ -0,0 +1,128 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Config_IoHandler
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Class to handle input/output for configuration params.
*
* @package MySQLDumper
* @subpackage Config_IoHandler
*/
class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface
{
/**
* Array with directories, where config files are located.
*
* @var array
*/
private $_configDirectories = array();
/**
* Handler for .ini files.
*
* @var Msd_Ini
*/
private $_iniConfig = null;
/**
* Name of the .ini file, where the config is stored.
*
* @var string
*/
private $_configFilename = null;
/**
* Configuration namespace in session.
*
* @var Zend_Session_Namespace
*/
private $_sessionNamespace = null;
/**
* Class constructor
*
* @param array $handlerOptions
*
* @return Msd_Config_IoHandler_Default
*/
public function __construct($handlerOptions = array())
{
if (isset($handlerOptions['directories'])) {
$this->_configDirectories = (array) $handlerOptions['directories'];
}
// Create new namespace for session access.
$this->_sessionNamespace = new Zend_Session_Namespace('Config');
}
/**
* Loads and returns a configuration from session or .ini file.
* If the config is read from .ini file, it is also stored to session.
*
* @param string $configFilename Name of the .ini file, where the config is stored.
*
* @return array
*/
public function load($configFilename)
{
// Retrieve config from session
$config = (array) $this->_sessionNamespace->config;
$this->_configFilename = $configFilename;
// Check whether the configuration has been loaded.
if (count($config) == 0) {
// Search for the config file in the given directories.
$this->_initIni();
$config = $this->_iniConfig->getIniData();
// Put configuration into session.
$this->_sessionNamespace->config = $config;
}
return $config;
}
/**
* Saves the configuration to session and .ini file.
*
* @param array $config Configuration to save.
*
* @return bool
*/
public function save($config)
{
if ($this->_iniConfig === null) {
$this->_initIni();
}
// Save config to session
$this->_sessionNamespace->config = $config;
// Save config to .ini file
$this->_iniConfig->setIniData($config);
return $this->_iniConfig->saveFile($this->_configFilename);
}
/**
* Initializes the .ini file handler and sets the full filename of the .ini file.
*
* @return void
*/
private function _initIni()
{
foreach ($this->_configDirectories as $configDir) {
$filename = rtrim($configDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->_configFilename;
if (file_exists($filename)) {
$this->_configFilename = $filename;
$this->_iniConfig = new Msd_Ini($filename);
break;
}
}
}
}

Datei anzeigen

@ -0,0 +1,51 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Config_IoHandler
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Interface for configuration IO-Handler.
*
* @package MySQLDumper
* @subpackage Config_IoHandler
*/
interface Msd_Config_IoHandler_Interface
{
/**
* Class constructor
*
* @abstract
*
* @param array $handlerOptions
*
* @return Msd_Config_IoHandler_Interface
*/
public function __construct($handlerOptions = array());
/**
* Loads and returns the configuration.
*
* @abstract
*
* @param string $configFilename
*
* @return array
*/
public function load($configFilename);
/**
* Saves the configuration.
*
* @abstract
*
* @param array $config
*
* @return bool
*/
public function save($config);
}