1
0
Fork 0

Continued to switch the old configuration handling to the new one.

Dieser Commit ist enthalten in:
DSB 2012-08-04 17:09:48 +00:00
Ursprung 025b5c339d
Commit ae87af916f
54 geänderte Dateien mit 501 neuen und 269 gelöschten Zeilen

Datei anzeigen

@ -16,8 +16,7 @@
* @package MySQLDumper
* @subpackage Action_Helper
*/
class Msd_Action_Helper_AssignConfigAndLanguage
extends Zend_Controller_Action_Helper_Abstract
class Msd_Action_Helper_AssignConfigAndLanguage extends Zend_Controller_Action_Helper_Abstract
{
/**
* Actual Zend_View instance
@ -36,9 +35,10 @@ class Msd_Action_Helper_AssignConfigAndLanguage
if ($controllerName == 'install') {
return;
}
$view = $this->getView();
$view->config = Msd_Configuration::getInstance();
$view->lang = Msd_Language::getInstance();
$view = $this->getView();
$view->config = Msd_Registry::getConfig();
$view->dynamicConfig = Msd_Registry::getDynamicConfig();
$view->lang = Msd_Language::getInstance();
}
/**
@ -51,7 +51,7 @@ class Msd_Action_Helper_AssignConfigAndLanguage
if (null !== $this->_view) {
return $this->_view;
} else {
$controller = $this->getActionController();
$controller = $this->getActionController();
$this->_view = $controller->view;
return $this->_view;
}

Datei anzeigen

@ -52,7 +52,7 @@ class Msd_Config
if (is_string($ioHandler)) {
$pluginLoader = new Zend_Loader_PluginLoader(
array(
'Msd_Config_IoHandler_' => APPLICATION_PATH . '/../library/Msd/Config/IoHandler/',
'Msd_Config_IoHandler_' => APPLICATION_PATH . '/../library/Msd/Config/IoHandler/',
'Module_Config_IoHandler_' => APPLICATION_PATH . '/../modules/library/Config/IoHandler/',
)
);
@ -79,6 +79,25 @@ class Msd_Config
public function load($configFilename)
{
$this->_config = $this->_ioHandler->load($configFilename);
$this->_setPaths();
}
/**
* Add paths to config
*
* @return void
*/
private function _setPaths()
{
$workRoot = realpath(APPLICATION_PATH . '/..') . '/work/';
$directories = array(
'work' => $workRoot,
'log' => $workRoot . 'log',
'backup' => $workRoot . 'backup',
'config' => $workRoot . 'config',
'iconPath' => 'css/' . $this->getParam('interface.theme', 'msd') . '/icons'
);
$this->setParam('paths', $directories);
}
/**
@ -95,13 +114,23 @@ class Msd_Config
/**
* Retrieves the value of a configuration parameter.
*
* @param string $paramName Name of the configuration parameter.
* @param string $paramName Name of the configuration parameter. May be prefixed with section.
* @param mixed $defaultValue Default value to return, if param isn't set.
*
* @return mixed
*/
public function getParam($paramName, $defaultValue = null)
{
// check for section e.g. interface.theme
if (strpos($paramName, '.') !== false) {
list($section, $paramName) = explode('.', $paramName);
if (isset($this->_config[$section][$paramName])) {
return $this->_config[$section][$paramName];
} else {
return $defaultValue;
}
}
if (isset($this->_config[$paramName])) {
return $this->_config[$paramName];
}
@ -120,7 +149,14 @@ class Msd_Config
*/
public function setParam($paramName, $paramValue)
{
$this->_config[$paramName] = $paramValue;
if (strpos('paramName', '.') !== false) {
list($section, $paramName) = explode('.', $paramName);
$this->_config[$section][$paramName] = $paramValue;
} else {
$this->_config[$paramName] = $paramValue;
}
if ($this->_autosave) {
$this->save();
}
@ -145,7 +181,7 @@ class Msd_Config
*/
public function setConfig($config)
{
$this->_config = (array) $config;
$this->_config = (array)$config;
if ($this->_autosave) {
$this->save();
}
@ -190,4 +226,18 @@ class Msd_Config
{
return $this->_autosave;
}
/**
* Get the title from a configuration file without aplying it.
*
* @param string $fileName The file name of the configuration
*
* @return string
*/
public function getConfigTitle($fileName)
{
$configData = parse_ini_file($this->getParam('paths.config') . '/' . $fileName . '.ini', true);
return $configData['general']['title'];
}
}

Datei anzeigen

@ -33,6 +33,7 @@ class Msd_Config_Dynamic
public function __construct($sessionNsName = 'Dynamic')
{
$this->_namespace = new Zend_Session_Namespace($sessionNsName);
$this->getDynamicValues();
}
/**
@ -64,4 +65,118 @@ class Msd_Config_Dynamic
{
$this->_namespace->$name = $value;
}
/**
* Read dynamic PHP config values
*
* @return Zend_Config
*/
public function getDynamicValues ()
{
$this->setParam('compression', self::_hasZlib());
$this->setParam('phpExtensions', str_replace(',', ', ', implode(', ', get_loaded_extensions())));
$phpRam = $this->_getPhpRam();
$this->setParam('phpRam', $phpRam);
$this->setParam('memoryLimit', round($phpRam * 1024 * 1024 * 0.9, 0));
$this->setParam('sendmailCall', $this->_getConfigSetting('sendmail_path'));
$this->setParam('safeMode', $this->_getConfigSetting('safe_mode', true));
$this->setParam('magicQuotesGpc', get_magic_quotes_gpc());
$disabledPhpFunctions = $this->_getConfigSetting('disable_functions');
$this->setParam('disabledPhpFunctions', str_replace(',', ', ', $disabledPhpFunctions));
$this->setParam('maxExecutionTime', $this->_getMaxExecutionTime());
$this->setParam('uploadMaxFilesize', $this->_getUploadMaxFilesize());
}
/**
* Read PHP's max_execution_time
*
* @return int
*/
private function _getMaxExecutionTime()
{
$maxExecutionTime =
$this->_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 function _getUploadMaxFilesize()
{
$uploadMaxFilesize = $this->_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 function _getPhpRam()
{
$ram = $this->_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 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

@ -117,7 +117,9 @@ class Msd_ConfigurationPhpValues
* 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 boolean $returnAsInt Whether to return value as integer
* @param bool $returnAsInt Whether to return value as integer
*
* @return mixed
*/
private function _getConfigSetting($varName, $returnAsInt = false)
{

Datei anzeigen

@ -0,0 +1,66 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Controller
* @version SVN: $Rev$
* @author $Author$
*/
/**
* General Controller Action class
*
* @package MySQLDumper
* @subpackage Controller
*/
class Msd_Controller_Action extends Zend_Controller_Action
{
/**
* @var Msd_Config
*/
protected $_config;
/**
* @var Msd_Config_Dynamic
*/
protected $_dynamicConfig;
/**
* Class constructor
*
* The request and response objects should be registered with the
* controller, as should be any additional optional arguments; these will be
* available via {@link getRequest()}, {@link getResponse()}, and
* {@link getInvokeArgs()}, respectively.
*
* When overriding the constructor, please consider this usage as a best
* practice and ensure that each is registered appropriately; the easiest
* way to do so is to simply call parent::__construct($request, $response,
* $invokeArgs).
*
* After the request, response, and invokeArgs are set, the
* {@link $_helper helper broker} is initialized.
*
* Finally, {@link init()} is called as the final action of
* instantiation, and may be safely overridden to perform initialization
* tasks; as a general rule, override {@link init()} instead of the
* constructor to customize an action controller's instantiation.
*
* @param Zend_Controller_Request_Abstract $request
* @param Zend_Controller_Response_Abstract $response
* @param array $invokeArgs Any additional invocation arguments
*
* @return Msd_Controller_Action
*/
public function __construct(
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response,
array $invokeArgs = array()
)
{
$this->_config = Msd_Registry::getConfig();
$this->_dynamicConfig = Msd_Registry::getDynamicConfig();
parent::__construct($request, $response, $invokeArgs);
}
}

Datei anzeigen

@ -124,13 +124,13 @@ abstract class Msd_Db
public static function getAdapter($options = null, $forceMysql = false)
{
if ($options === null) {
$config = Msd_Configuration::getInstance();
$config = Msd_Registry::getConfig();
$options = array(
'host' => $config->get('config.dbuser.host'),
'user' => $config->get('config.dbuser.user'),
'pass' => $config->get('config.dbuser.pass'),
'port' => (int) $config->get('config.dbuser.port'),
'socket' => $config->get('config.dbuser.socket'),
'host' => $config->getParam('dbuser.host'),
'user' => $config->getParam('dbuser.user'),
'pass' => $config->getParam('dbuser.pass'),
'port' => (int) $config->getParam('dbuser.port'),
'socket' => $config->getParam('dbuser.socket'),
);
}
if (function_exists('mysqli_connect') && !$forceMysql) {

Datei anzeigen

@ -62,8 +62,8 @@ class Msd_Dump
*/
private function _getDbsToBackup()
{
$config = Msd_Configuration::getInstance();
$databases = $config->get('dynamic.databases');
$dynamicConfig = Msd_Registry::getDynamicConfig();
$databases = $dynamicConfig->getParam('dynamic.databases');
// first check if any db is marked to be dumped
$dbToDumpExists = false;
if (!empty($databases)) {
@ -77,7 +77,7 @@ class Msd_Dump
}
if (!$dbToDumpExists) {
// no db selected for dump -> set actual db to be dumped
$index = $config->get('dynamic.dbActual');
$index = $dynamicConfig->getParam('dbActual');
$this->dbsToBackup[$index] = array();
$this->dbsToBackup[$index]['dump'] = 1;
}
@ -203,4 +203,4 @@ class Msd_Dump
);
}
}
}
}

Datei anzeigen

@ -58,9 +58,9 @@ class Msd_File
*/
public static function getLatestBackupInfo()
{
$config = Msd_Configuration::getInstance();
$config = Msd_Registry::getConfig();
$latestBackup = array();
$dir = new DirectoryIterator($config->get('paths.backup'));
$dir = new DirectoryIterator($config->getParam('paths.backup'));
foreach ($dir as $file) {
if ($file->isFile()) {
$fileMtime = $file->getMTime();
@ -84,11 +84,12 @@ class Msd_File
*/
public static function getConfigNames()
{
$config = Msd_Configuration::getInstance();
$configPath = $config->get('paths.config');
$config = Msd_Registry::getConfig();
$configPath = $config->getParam('paths.config');
if (!is_readable($configPath)) {
return array();
}
$dir = new DirectoryIterator($configPath);
$files = array();
foreach ($dir as $file) {

Datei anzeigen

@ -28,8 +28,8 @@ class Msd_File_Dump extends Msd_File
*/
public static function getStatusline($filename)
{
$config = Msd_Configuration::getInstance();
$path = $config->get('paths.backup'). DS;
$config = Msd_Registry::getConfig();
$path = $config->getParam('paths.backup'). '/';
if (strtolower(substr($filename, -3)) == '.gz') {
$fileHandle = gzopen($path . $filename, "r");
if ($fileHandle === false) {

Datei anzeigen

@ -21,7 +21,7 @@ class Msd_Language
/**
* Instance
*
* @var Msd_Configuration
* @var Msd_Language
*/
private static $_instance = NULL;
@ -42,12 +42,12 @@ class Msd_Language
/**
* Constructor gets the configuration params
*
* @return array
* @return Msd_Language
*/
private function __construct ()
private function __construct()
{
$config = Msd_Configuration::getInstance();
$language = $config->get('config.interface.language');
$config = Msd_Registry::getConfig();
$language = $config->getParam('interface.language', 'en');
$this->loadLanguage($language);
}
@ -61,8 +61,8 @@ class Msd_Language
public function loadLanguage($language)
{
$this->_baseLanguageDir = APPLICATION_PATH . '/language/';
$file = $this->_baseLanguageDir . $language . '/lang.php';
$translator = $this->getTranslator();
$file = $this->_baseLanguageDir . $language . '/lang.php';
$translator = $this->getTranslator();
if ($translator === null) {
$translator = new Zend_Translate('array', $file, $language);
} else {
@ -70,16 +70,19 @@ class Msd_Language
array(
'adapter' => 'array',
'content' => $file,
'locale' => $language
'locale' => $language
)
);
}
$this->setTranslator($translator);
Zend_Registry::set('Zend_Translate', $translator);
}
/**
* No cloning for singleton
*
* @throws Msd_Exception
*
* @return void
*/
public function __clone()
@ -90,25 +93,26 @@ class Msd_Language
/**
* Magic getter to keep syntax in rest of script short
*
* @param mixed $var
* @param mixed $name Name of language var to translate
*
* @return mixed
*/
public function __get ($property)
public function __get($name)
{
$translated = $this->getTranslator()->_($property);
if ($translated == $property && substr($property, 0, 2) == 'L_') {
$translated = $this->getTranslator()->_($name);
if ($translated == $name && substr($name, 0, 2) == 'L_') {
// no translation found -> remove prefix L_
return substr($property, 2);
return substr($name, 2);
}
return $translated;
}
/**
* Returns the single instance
*
* @return Msd_Language
*/
public static function getInstance ()
public static function getInstance()
{
if (NULL == self::$_instance) {
self::$_instance = new self;
@ -126,7 +130,7 @@ class Msd_Language
*/
public function translateZendId($zendMessageId, $messageText = '')
{
if (substr($zendMessageId, 0, 6) =='access' && $messageText > '') {
if (substr($zendMessageId, 0, 6) == 'access' && $messageText > '') {
// message is already translated by validator access
return $messageText;
}

Datei anzeigen

@ -29,7 +29,7 @@ class Msd_Log
/**
* Init file handles
*
* @return void
* @return Msd_Log
*/
public function __construct()
{
@ -41,8 +41,8 @@ class Msd_Log
$this->handle[self::ERROR] = false;
// get config
$config = Msd_Configuration::getInstance();
$this->_paths = (object)$config->get('paths');
$config = Msd_Registry::getConfig();
$this->_paths = (object) $config->getParam('paths');
}
/**

Datei anzeigen

@ -31,7 +31,7 @@ class Msd_TaskManager
/**
* Instance
*
* @var Msd_Configuration
* @var Msd_TaskManager
*/
private static $_instance = NULL;
@ -48,12 +48,10 @@ class Msd_TaskManager
*
* Get task list from session or init an empty list.
*
* @param string $taskType Task type to get or create.
* Defaults to "backupTasks".
* @param boolean Whether to create a new task list and delete all entries
* or to get it from the session
* @param string $taskType The name of the task type
* @param boolean $clear Whether to clear all tasks
*
* @return void
* @return Msd_TaskManager
*/
private function __construct($taskType, $clear = false)
{
@ -69,15 +67,12 @@ class Msd_TaskManager
/**
* Returns the task manager 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.
* @param string $taskType The name of the task type
* @param boolean $clear Whether to clear all tasks
*
* @return Msd_Configuration
* @return Msd_TaskManager
*/
public static function getInstance($taskType = 'backupTasks',
$clear = false)
public static function getInstance($taskType = 'backupTasks', $clear = false)
{
if (null == self::$_instance) {
self::$_instance = new self($taskType, $clear);

Datei anzeigen

@ -246,6 +246,7 @@ class Msd_User
$configFile = $files[0];
}
}
Msd_Configuration::getInstance($configFile, true);
$config = Msd_Registry::getConfig();
$config->load($configFile . '.ini');
}
}