From 2ad562bd5dffea2f2758c61ba160dd8d6c592880 Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Mon, 6 Mar 2017 21:07:09 +0100
Subject: [PATCH] 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.

---
 extension/qfq/qfq/store/Config.php | 86 ++++++++++++++++++++++++++++++
 extension/qfq/qfq/store/Store.php  | 59 ++------------------
 2 files changed, 89 insertions(+), 56 deletions(-)
 create mode 100644 extension/qfq/qfq/store/Config.php

diff --git a/extension/qfq/qfq/store/Config.php b/extension/qfq/qfq/store/Config.php
new file mode 100644
index 000000000..fe646b5eb
--- /dev/null
+++ b/extension/qfq/qfq/store/Config.php
@@ -0,0 +1,86 @@
+<?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
diff --git a/extension/qfq/qfq/store/Store.php b/extension/qfq/qfq/store/Store.php
index 8ef27d154..ea95f84f3 100644
--- a/extension/qfq/qfq/store/Store.php
+++ b/extension/qfq/qfq/store/Store.php
@@ -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
-- 
GitLab