Commit 2ad562bd authored by Carsten  Rose's avatar Carsten Rose
Browse files

Config.php: created new class to separate reading of config.qfq.ini

Store.php: reading of config.qfq.ini moved to new class Config.php.
parent 1b25d9bd
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 3/6/17
* Time: 8:47 PM
*/
namespace qfq;
use qfq;
require_once(__DIR__ . '/../../qfq/Constants.php');
class Config {
/**
* Read config.qfq.ini.
*
* @throws CodeException
* @throws qfq\UserFormException
*/
public function readConfig($fileConfigIni = '') {
if ($fileConfigIni == '') {
// Production Path to CONFIG_INI
$fileConfigIni = __DIR__ . '/../../../../../' . CONFIG_INI;
if (!file_exists($fileConfigIni)) {
// PHPUnit Path to CONFIG_INI
$fileConfigIni = __DIR__ . '/../../../' . CONFIG_INI;
}
}
try {
$config = parse_ini_file($fileConfigIni, false);
} catch (\Exception $e) {
throw new qfq\UserFormException ("Error read file " . $fileConfigIni . ": " . $e->getMessage(), ERROR_IO_READ_FILE);
}
$config = self::renameConfigElements($config);
return $config;
}
/**
* Rename Elements defined in config.qfq.ini to more appropriate in user interaction.
* E.g.: in config.qfq.ini everything is in upper case and word space is '_'. In Form.parameter it's lowercase and camel hook.
*
* @param array $config
* @return array
*/
private static function renameConfigElements(array $config) {
// oldname > newname
$setting = [
[SYSTEM_FORM_BS_LABEL_COLUMNS, F_BS_LABEL_COLUMNS],
[SYSTEM_FORM_BS_INPUT_COLUMNS, F_BS_INPUT_COLUMNS],
[SYSTEM_FORM_BS_NOTE_COLUMNS, F_BS_NOTE_COLUMNS],
[SYSTEM_FORM_DATA_PATTERN_ERROR, F_FE_DATA_PATTERN_ERROR],
[SYSTEM_FORM_DATA_REQUIRED_ERROR, F_FE_DATA_REQUIRED_ERROR],
[SYSTEM_FORM_DATA_MATCH_ERROR, F_FE_DATA_MATCH_ERROR],
[SYSTEM_FORM_DATA_ERROR, F_FE_DATA_ERROR],
[SYSTEM_CSS_CLASS_QFQ_FORM, F_CLASS],
[SYSTEM_CSS_CLASS_QFQ_FORM_PILL, F_CLASS_PILL],
[SYSTEM_CSS_CLASS_QFQ_FORM_BODY, F_CLASS_BODY],
[SYSTEM_FORM_BUTTON_ON_CHANGE_CLASS, F_BUTTON_ON_CHANGE_CLASS],
];
foreach ($setting as $row) {
$oldName = $row[0];
$newName = $row[1];
if (isset($config[$oldName])) {
$config[$newName] = $config[$oldName];
if ($oldName != $newName) {
unset($config[$oldName]);
}
}
}
return $config;
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/store/Sip.php');
//require_once(__DIR__ . '/../../qfq/store/Session.php');
require_once(__DIR__ . '/../../qfq/Database.php');
require_once(__DIR__ . '/../../qfq/store/Config.php');
/*
* Stores:
......@@ -182,23 +183,8 @@ class Store {
*/
private static function fillSystemStore($fileConfigIni = '') {
if ($fileConfigIni == '') {
// Production Path to CONFIG_INI
$fileConfigIni = __DIR__ . '/../../../../../' . CONFIG_INI;
if (!file_exists($fileConfigIni)) {
// PHPUnit Path to CONFIG_INI
$fileConfigIni = __DIR__ . '/../../../' . CONFIG_INI;
}
}
try {
$config = parse_ini_file($fileConfigIni, false);
} catch (\Exception $e) {
throw new qfq\UserFormException ("Error read file " . $fileConfigIni . ": " . $e->getMessage(), ERROR_IO_READ_FILE);
}
$config = self::renameConfigElements($config);
$cfg = new Config();
$config = $cfg->readConfig($fileConfigIni);
// Defaults
Support::setIfNotSet($config, SYSTEM_DATE_FORMAT, 'yyyy-mm-dd');
......@@ -219,45 +205,6 @@ class Store {
self::setStore($config, STORE_SYSTEM, true);
}
/**
* Rename Elements defined in config.qfq.ini to more appropriate in user interaction.
* E.g.: in config.qfq.ini everything is in upper case and word space is '_'. In Form.parameter it's lowercase and camel hook.
*
* @param array $config
* @return array
*/
private static function renameConfigElements(array $config) {
// oldname > newname
$setting = [
[SYSTEM_FORM_BS_LABEL_COLUMNS, F_BS_LABEL_COLUMNS],
[SYSTEM_FORM_BS_INPUT_COLUMNS, F_BS_INPUT_COLUMNS],
[SYSTEM_FORM_BS_NOTE_COLUMNS, F_BS_NOTE_COLUMNS],
[SYSTEM_FORM_DATA_PATTERN_ERROR, F_FE_DATA_PATTERN_ERROR],
[SYSTEM_FORM_DATA_REQUIRED_ERROR, F_FE_DATA_REQUIRED_ERROR],
[SYSTEM_FORM_DATA_MATCH_ERROR, F_FE_DATA_MATCH_ERROR],
[SYSTEM_FORM_DATA_ERROR, F_FE_DATA_ERROR],
[SYSTEM_CSS_CLASS_QFQ_FORM, F_CLASS],
[SYSTEM_CSS_CLASS_QFQ_FORM_PILL, F_CLASS_PILL],
[SYSTEM_CSS_CLASS_QFQ_FORM_BODY, F_CLASS_BODY],
[SYSTEM_FORM_BUTTON_ON_CHANGE_CLASS, F_BUTTON_ON_CHANGE_CLASS],
];
foreach ($setting as $row) {
$oldName = $row[0];
$newName = $row[1];
if (isset($config[$oldName])) {
$config[$newName] = $config[$oldName];
if ($oldName != $newName) {
unset($config[$oldName]);
}
}
}
return $config;
}
/**
* QFQ might be called via Typo3 (index.php) or directly via AJAX (directory: api). The
* @param array $config
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment