From 6dae0556b242bbee3ab2c9f1b0f71f3ebe988abe Mon Sep 17 00:00:00 2001 From: Diederik de Groot Date: Tue, 18 Feb 2020 18:31:41 +0100 Subject: [PATCH] Added comments to config.php to clarify use Signed-off-by: Diederik de Groot --- lib/config.php | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/config.php b/lib/config.php index dca4825..194424e 100644 --- a/lib/config.php +++ b/lib/config.php @@ -65,7 +65,7 @@ class ConfigParser { '; function __construct($base_path, $config_file) { - # Merge config + # Merge defaults with ini file $default_config = $this->parse_multi_ini_string($this->defaults,true,INI_SCANNER_TYPED); $ini_config = $this->parse_multi_ini_file("$base_path/$config_file", true, INI_SCANNER_TYPED); if (!empty($ini_config)) { @@ -77,21 +77,26 @@ class ConfigParser { $this->config = $config; } - private $tree_structure = Array( - 'etc' => array('parent' => NULL, "strip" => true), - 'tftproot' => array('parent' => NULL, "strip" => true), - 'settings' => array('parent' => 'tftproot', "strip" => true), - 'wallpapers' => array('parent' => 'tftproot', "strip" => false), - 'ringtones' => array('parent' => 'tftproot', "strip" => true), - 'locales' => array('parent' => 'tftproot', "strip" => true), - 'firmware' => array('parent' => 'tftproot', "strip" => true), - 'languages' => array('parent' => 'locales', "strip" => false), - 'countries' => array('parent' => 'locales', "strip" => false), - ); - function replaceSubdirTreeStructure($tmpSubdirs) { - # replace config['subdirs'] paths using tree_structure + /*! + * replace config['subdirs'] paths using tree_structure + * method imported from old version (and rewritten) + * Note: Still not sure if we actually need to do all this + */ + private function replaceSubdirTreeStructure($tmpSubdirs) { + $tree_structure = Array( + 'etc' => array('parent' => NULL, "strip" => true), + 'tftproot' => array('parent' => NULL, "strip" => true), + 'settings' => array('parent' => 'tftproot', "strip" => true), + 'wallpapers' => array('parent' => 'tftproot', "strip" => false), + 'ringtones' => array('parent' => 'tftproot', "strip" => true), + 'locales' => array('parent' => 'tftproot', "strip" => true), + 'firmware' => array('parent' => 'tftproot', "strip" => true), + 'languages' => array('parent' => 'locales', "strip" => false), + 'countries' => array('parent' => 'locales', "strip" => false), + ); + $subdirs = Array(); - foreach ($this->tree_structure as $key => $value) { + foreach ($tree_structure as $key => $value) { if (!empty($tmpSubdirs[$key])) { if (substr($tmpSubdirs[$key], 0, 1) !== "/") { if (!$value['parent']) { @@ -110,6 +115,11 @@ class ConfigParser { return $subdirs; } + /*! + * config parser that understands multidimensional ini entries + * using "." as the dimension separator + * standin replacement for parse_ini_string + */ private function parse_multi_ini_string($string, $process_sections = false, $scanner_mode = INI_SCANNER_NORMAL) { $explode_str = '.'; $escape_char = "'"; @@ -153,9 +163,13 @@ class ConfigParser { } return $data; } - + + /*! + * config file parser that understands multidimensional ini entries + * using "." as the dimension separator + * standin replacement for parse_ini_file + */ private function parse_multi_ini_file($file, $process_sections = false, $scanner_mode = INI_SCANNER_NORMAL) { - // load ini file the normal way $string = file_get_contents($file); return $this->parse_multi_ini_string($string, $process_sections, $scanner_mode); return $data;