1
0
Fork 0
- Changed old configuration to new class for installation
- removed old classes
Dieser Commit ist enthalten in:
DSB 2012-08-21 20:22:56 +00:00
Ursprung c0be3ce898
Commit 4a569043a6
18 geänderte Dateien mit 345 neuen und 753 gelöschten Zeilen

Datei anzeigen

@ -35,7 +35,13 @@ class Msd_Action_Helper_AssignConfigAndLanguage extends Zend_Controller_Action_H
if ($controllerName == 'install') {
return;
}
$view = $this->getView();
$view = $this->getView();
if (Msd_Registry::getConfigFilename() == 'defaultConfig.ini') {
$redirectUrl = $view->serverUrl() . $view->url(array('controller' => 'install', 'action' => 'index', null, true));
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl($redirectUrl);
}
$view->config = Msd_Registry::getConfig();
$view->dynamicConfig = Msd_Registry::getDynamicConfig();
$view->lang = Msd_Language::getInstance();

Datei anzeigen

@ -107,8 +107,14 @@ class Msd_Config
*
* @return bool
*/
public function save()
public function save($configFilenameAndPath = null)
{
//$configFilename = $this->getParam('configFile');
//echo "Dateiname: ". $configFilename;
if ($configFilenameAndPath !== null) {
$this->_ioHandler->setConfigFilename(basename($configFilenameAndPath));
}
return $this->_ioHandler->save($this->_config);
}

Datei anzeigen

@ -79,7 +79,7 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface
if (count($config) == 0) {
// Search for the config file in the given directories.
$this->_initIni();
$this->_initIni($config);
$config = $this->_iniConfig->getIniData();
// Put configuration into session.
$this->_sessionNamespace->config = $config;
@ -88,6 +88,16 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface
return $config;
}
/**
* Set configuration file name
*
* @param string $configFilename File name of configuration file (without path)
*/
public function setConfigFilename($configFilename)
{
$this->_configFilename = $configFilename;
}
/**
* Saves the configuration to session and .ini file.
*
@ -98,7 +108,7 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface
public function save($config)
{
if ($this->_iniConfig === null) {
$this->_initIni();
$this->_initIni($config);
}
// Save config to session
$this->_sessionNamespace->config = $config;
@ -111,17 +121,21 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface
/**
* Initializes the .ini file handler and sets the full filename of the .ini file.
*
* @param array Configuration as array
*
* @return void
*/
private function _initIni()
private function _initIni($config)
{
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;
return;
}
}
$this->_iniConfig = new Msd_Ini();
$this->_iniConfig->setIniData($config);
}
}

Datei anzeigen

@ -1,317 +0,0 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Configuration
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Configuration class implemented as singleton
*
* Handles getting and setting of configuration variables
*
* @package MySQLDumper
* @subpackage Configuration
*/
class Msd_Configuration
{
/**
* Instance
*
* @var Msd_Configuration
*/
private static $_instance = NULL;
/**
* Configuration params
*
* @var StdClass
*/
private $_data = null;
/**
* Session to old values
*
* @var Zend_Session_Namespace
*/
private $_session = null;
/**
* Constructor
*
* @param string $configName The name of the configuration file to load.
* If not set we will load the config from
* session if present.
* @param bool $forceLoading Force loading of configuration from file
*/
private function __construct($configName = '', $forceLoading = false)
{
$this->_session = new Zend_Session_Namespace('MySQLDumper');
if ($forceLoading === false && isset($this->_session->dynamic->configFile)) {
$this->loadConfigFromSession();
return;
}
$this->_data = new stdClass;
if ($configName == '') {
$configName = 'defaultConfig';
}
$this->_data->dynamic = Msd_ConfigurationPhpValues::getDynamicValues();
$this->_data->paths = $this->_loadUserDirectories();
$this->loadConfiguration($configName);
$this->set('dynamic.configFile', $configName);
$defaultDb = $this->get('config.dbuser.defaultDb');
if ($defaultDb != '') {
$this->set('dynamic.dbActual', $defaultDb);
}
$this->saveConfigToSession();
}
/**
* No cloning for singleton
*
* @return void
*/
public function __clone()
{
throw new Msd_Exception('Cloning is not allowed');
}
/**
* Returns the configuration instance
*
* @param string $configName The name of the configuration file to load.
* If not set we will load the config from
* session if present.
* @param boolean $forceLoading If set the config will be read from file.
*
* @return Msd_Configuration
*/
public static function getInstance($configName = '', $forceLoading = false)
{
if (null == self::$_instance) {
self::$_instance = new self($configName, $forceLoading);
}
if ($forceLoading) {
self::$_instance->loadConfiguration($configName, true);
}
return self::$_instance;
}
/**
* Set a key to a val
*
* @param string $configPath Must begin with "config", "dynamic" or "paths"
* @param string $val The value to set
*
* @return Msd_Configuration
*/
public function set($configPath, $val)
{
$args = explode('.', $configPath);
if (!in_array($args[0], array('config', 'paths', 'dynamic'))) {
$msg = 'Trying to set config value with illegal key. First key '
. 'must be "config", "paths" or "dynamic"';
throw new Msd_Exception($msg);
}
switch (count($args)) {
case 2:
list($type, $var) = $args;
$this->_data->$type->$var = $val;
break;
case 3:
list($type, $section, $var) = $args;
$this->_data->$type->$section->$var = $val;
break;
default:
$backTrace = debug_backtrace(false);
throw new Msd_Exception(
'Path couldn\'t be set!' . PHP_EOL . $configPath .
' invoked from ' . $backTrace[0]['file'] . '[' .
$backTrace[0]['line'] . ']',
E_USER_NOTICE
);
}
return $this;
}
/**
* Get a config parameter
*
* If first part isn't config, paths or dynamic, we assume config is meant.
*
* @param string $key Path to get
*
* @return string|array
*/
public function get($key)
{
$params = explode('.', $key);
if (!in_array($params[0], array('config', 'paths', 'dynamic'))) {
$msg = 'Trying to get config value with illegal key. First key '
. 'must be "config", "paths" or "dynamic"';
throw new Msd_Exception($msg);
}
$values = $this->_data->$params[0];
if (!is_array($values)) {
$values = $this->_data->$params[0]->toArray();
}
if (sizeof($params) == 1) {
return $values;
}
unset($params[0]);
foreach ($params as $index) {
if (isset($values[$index])) {
$values = $values[$index];
} else {
$values = null;
break;
}
}
return $values;
}
/**
* Save configurations to file
*
* @param string $fileName Name of configuration without extension .ini
* @param array $configArray Data to save as array
*
* @return void
*/
public function save($fileName = null, $configArray = null)
{
if ($fileName === null) {
$fileName = $this->get('dynamic.configFile');
}
$fileName .= '.ini';
// save branch config and skip groups "dynamic" and "paths"
if ($configArray !== null) {
$configData = new Zend_Config($configArray, true);
} else {
$configData = $this->_data->config;
}
$configWriter = new Zend_Config_Writer_Ini(
array(
'filename' => $this->get('paths.config') . '/' . $fileName,
'config' => $configData,
)
);
$configWriter->write();
$this->_data->config = $configData;
$this->set('dynamic.configFile', basename($fileName, '.ini'));
$this->saveConfigToSession();
}
/**
* Save config to session
*
* @return void
*/
public function saveConfigToSession()
{
$this->_session->unsetAll();
$this->_session->config = $this->_data->config;
$this->_session->dynamic = $this->_data->dynamic;
$this->_session->paths = $this->_data->paths;
}
/**
* Get config from session
*
* @return object
*/
public function loadConfigFromSession()
{
if (isset($this->_session->config)) {
$this->_data->config = $this->_session->config;
}
if (isset($this->_session->dynamic)) {
$this->_data->dynamic = $this->_session->dynamic;
}
if (isset($this->_session->paths)) {
$this->_data->paths = $this->_session->paths;
}
}
/**
* Load configuration file
*
* @param string $configName The configuration file to load
* @param boolean $applyValues Whether to apply loaded values to config
*
* @return Zend_Config_ini Loaded configuration as Zend_Config_Ini
*/
public function loadConfiguration($configName, $applyValues = true)
{
$this->_loadUserDirectories();
if ($configName != 'defaultConfig') {
$configName .= '.ini';
$configPath = $this->get('paths.config');
$configFile = $configPath . '/' . $configName;
} else {
// special case - defaultConfig.ini is in application/configs
$configFile = realpath(APPLICATION_PATH . '/configs') . '/defaultConfig.ini';
}
if (!is_readable($configFile)) {
throw new Msd_Exception(
'Couldn\'t read configuration file ' . $configFile
);
}
$options = array('allowModifications' => true);
$config = new Zend_Config_Ini($configFile, null, $options);
if (!$applyValues) {
return $config;
}
$this->_data->config = null;
$this->_data->config = $config;
$this->set('dynamic.configFile', basename($configFile, '.ini'));
$iconPath = 'css/' . $this->get('config.interface.theme') . '/icons';
$this->set('paths.iconpath', $iconPath);
$this->saveConfigToSession();
return $config;
}
/**
* Get user directories and save them to config
*
* @return Zend_Config Directories as object
*/
private function _loadUserDirectories()
{
// set paths
$workRoot = realpath(APPLICATION_PATH . '/..') . '/work/';
$directories = array(
'work' => $workRoot,
'log' => $workRoot . 'log',
'backup' => $workRoot . 'backup',
'config' => $workRoot . 'config'
);
return new Zend_Config($directories, true);
}
/**
* Return name of configuration
*
* @return string
*/
public function getTitle()
{
return $this->get('config.general.title');
}
/**
* Reloads the configuration from the current ini file.
*
* @return void
*/
public function reloadConfig()
{
$this->loadConfiguration($this->get('dynamic.configFile'));
}
}

Datei anzeigen

@ -1,138 +0,0 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Configuration
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Helper for getting dynamic configuration values like phpRam etc.
*
* @package MySQLDumper
* @subpackage Configuration
*/
class Msd_ConfigurationPhpValues
{
/**
* Read dynamic PHP config values
*
* @return Zend_Config
*/
public static function getDynamicValues ()
{
$phpRam = self::_getPhpRam();
$dynConfig = array(
'sendmailCall' => self::_getConfigSetting('sendmail_path'),
'safeMode' => self::_getConfigSetting('safe_mode', true),
'magicQuotesGpc' => get_magic_quotes_gpc(),
'disabledPhpFunctions' =>
str_replace(
',',
', ',
self::_getConfigSetting('disable_functions')
),
'maxExecutionTime' => self::_getMaxExecutionTime(),
'uploadMaxFilesize' => self::_getUploadMaxFilesize(),
'phpextensions' => implode(', ', get_loaded_extensions()),
'phpRam' => $phpRam,
'memoryLimit' => round($phpRam * 1024 * 1024 * 0.9, 0),
'compression' => self::_hasZlib(),
);
return new Zend_Config($dynConfig, true);
}
/**
* Read PHP's max_execution_time
*
* @return int
*/
private static function _getMaxExecutionTime()
{
$maxExecutionTime =
self::_getConfigSetting('max_execution_time', true);
if ($maxExecutionTime <= 5) {
// we didn't get the real value from the server - some deliver "-1"
$maxExecutionTime = 30;
} elseif ($maxExecutionTime > 30) {
// we don't use more than 30 seconds to avoid brower timeouts
$maxExecutionTime = 30;
}
return $maxExecutionTime;
}
/**
* Get PHP's upload_max_filesize
*
* @return int
*/
private static function _getUploadMaxFilesize()
{
$uploadMaxFilesize = self::_getConfigSetting('upload_max_filesize');
// Is value in Megabytes? If yes create output
if (strpos($uploadMaxFilesize, 'M')) {
$uploadMaxFilesize = str_replace('M', '', $uploadMaxFilesize);
$uploadMaxFilesize = trim($uploadMaxFilesize);
// re-calculate to Bytes
$uploadMaxFilesize *= 1024 * 1024;
}
return (int) $uploadMaxFilesize;;
}
/**
* Get PHP's ram size
*
* @return integer The memory limit in MB
*/
private static function _getPhpRam()
{
$ram = self::_getConfigSetting('memory_limit');
// we don't trust the value delivered by server config if < 16
if ($ram < 16) {
$ram = 16;
}
return $ram;
}
/**
* Detect if zlib is installed
*
* @return boolean
*/
private static function _hasZlib()
{
$zlib = false;
$extensions = get_loaded_extensions();
if (in_array('zlib', $extensions)) {
$zlib = true;
};
return (boolean) $zlib;
}
/**
* Returns a PHP-Setting from ini
*
* First try to read via ini_get(), then fall back to get_cfg_var()
*
* @param string $varName The name of the setting to read
* @param bool $returnAsInt Whether to return value as integer
*
* @return mixed
*/
private function _getConfigSetting($varName, $returnAsInt = false)
{
$value = @ini_get($varName);
// fallback if ini_get doesn't work
if ($value == '' || $value === null) {
$value = @get_cfg_var($varName);
}
if ($returnAsInt) {
$value = (int) $value;
}
return $value;
}
}

Datei anzeigen

@ -26,6 +26,11 @@ class Msd_Controller_Action extends Zend_Controller_Action
*/
protected $_dynamicConfig;
/**
* @var Msd_Language
*/
protected $_lang;
/**
* Class constructor
*
@ -59,8 +64,9 @@ class Msd_Controller_Action extends Zend_Controller_Action
array $invokeArgs = array()
)
{
$this->_config = Msd_Registry::getConfig();
$this->_config = Msd_Registry::getConfig();
$this->_dynamicConfig = Msd_Registry::getDynamicConfig();
$this->_lang = Msd_Language::getInstance();
parent::__construct($request, $response, $invokeArgs);
}
}

Datei anzeigen

@ -21,21 +21,21 @@ class Msd_Registry extends Zend_Registry
*
* @const string
*/
const CONFIG_FILENAME_KEY = '_configFilename';
const CONFIG_FILENAME_KEY = 'configFilename';
/**
* Key for the dynamic configuration. This is used inside the registry.
*
* @const string
*/
const DYNAMIC_CONFIG_KEY = '_dynamic';
const DYNAMIC_CONFIG_KEY = 'Dynamic';
/**
* Key for the configuration. This is used inside the registry.
*
* @const string
*/
const CONFIG_KEY = '_config';
const CONFIG_KEY = 'Config';
/**
* Returns the config instance if it has been registered, returns null otherwise.