Added comments to config.php to clarify use

Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
Diederik de Groot
2020-02-18 18:31:41 +01:00
parent 3a4286628e
commit 6dae0556b2

View File

@@ -65,7 +65,7 @@ class ConfigParser {
'; ';
function __construct($base_path, $config_file) { 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); $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); $ini_config = $this->parse_multi_ini_file("$base_path/$config_file", true, INI_SCANNER_TYPED);
if (!empty($ini_config)) { if (!empty($ini_config)) {
@@ -77,21 +77,26 @@ class ConfigParser {
$this->config = $config; $this->config = $config;
} }
private $tree_structure = Array( /*!
'etc' => array('parent' => NULL, "strip" => true), * replace config['subdirs'] paths using tree_structure
'tftproot' => array('parent' => NULL, "strip" => true), * method imported from old version (and rewritten)
'settings' => array('parent' => 'tftproot', "strip" => true), * Note: Still not sure if we actually need to do all this
'wallpapers' => array('parent' => 'tftproot', "strip" => false), */
'ringtones' => array('parent' => 'tftproot', "strip" => true), private function replaceSubdirTreeStructure($tmpSubdirs) {
'locales' => array('parent' => 'tftproot', "strip" => true), $tree_structure = Array(
'firmware' => array('parent' => 'tftproot', "strip" => true), 'etc' => array('parent' => NULL, "strip" => true),
'languages' => array('parent' => 'locales', "strip" => false), 'tftproot' => array('parent' => NULL, "strip" => true),
'countries' => array('parent' => 'locales', "strip" => false), 'settings' => array('parent' => 'tftproot', "strip" => true),
); 'wallpapers' => array('parent' => 'tftproot', "strip" => false),
function replaceSubdirTreeStructure($tmpSubdirs) { 'ringtones' => array('parent' => 'tftproot', "strip" => true),
# replace config['subdirs'] paths using tree_structure '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(); $subdirs = Array();
foreach ($this->tree_structure as $key => $value) { foreach ($tree_structure as $key => $value) {
if (!empty($tmpSubdirs[$key])) { if (!empty($tmpSubdirs[$key])) {
if (substr($tmpSubdirs[$key], 0, 1) !== "/") { if (substr($tmpSubdirs[$key], 0, 1) !== "/") {
if (!$value['parent']) { if (!$value['parent']) {
@@ -110,6 +115,11 @@ class ConfigParser {
return $subdirs; 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) { private function parse_multi_ini_string($string, $process_sections = false, $scanner_mode = INI_SCANNER_NORMAL) {
$explode_str = '.'; $explode_str = '.';
$escape_char = "'"; $escape_char = "'";
@@ -154,8 +164,12 @@ class ConfigParser {
return $data; 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) { 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); $string = file_get_contents($file);
return $this->parse_multi_ini_string($string, $process_sections, $scanner_mode); return $this->parse_multi_ini_string($string, $process_sections, $scanner_mode);
return $data; return $data;