Use Boolean in tree_base data

Simplify config['subdirs'] substitution

Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
Diederik de Groot
2020-02-16 01:30:52 +01:00
parent fcf0495a38
commit 00b1241dfc
2 changed files with 19 additions and 20 deletions

View File

@@ -17,14 +17,14 @@ $base_config = Array(
) )
); );
$tree_base = Array( $tree_base = Array(
'settings' => array('path' => 'tftproot', "strip" => 1), 'settings' => array('path' => 'tftproot', "strip" => TRUE),
'wallpapers' => array('path' => 'tftproot', "strip" => 0), 'wallpapers' => array('path' => 'tftproot', "strip" => FALSE),
'ringtones' => array('path' => 'tftproot', "strip" => 1), 'ringtones' => array('path' => 'tftproot', "strip" => TRUE),
'locales' => array('path' => 'tftproot', "strip" => 1), 'locales' => array('path' => 'tftproot', "strip" => TRUE),
'firmware' => array('path' => 'tftproot', "strip" => 1), 'firmware' => array('path' => 'tftproot', "strip" => TRUE),
'languages' => array('path' => 'locales', "strip" => 0), 'languages' => array('path' => 'locales', "strip" => FALSE),
'countries' => array('path' => 'locales', "strip" => 0), 'countries' => array('path' => 'locales', "strip" => FALSE),
'default_language' => array('path' => 'locales', "strip" => 1), 'default_language' => array('path' => 'locales', "strip" => TRUE),
); );
# Merge config # Merge config
@@ -33,19 +33,18 @@ if (!empty($ini_array)) {
$config = array_merge($base_config, $ini_array); $config = array_merge($base_config, $ini_array);
} }
# rewrite config['subdirs'] paths using tree_base data # build new config['subdirs'] paths substituting bases from tree_base
# Not sure if this is a good way
foreach ($tree_base as $key => $value) { foreach ($tree_base as $key => $value) {
if (!empty($config['subdirs'][$key])) { $tmp = $config;
if (substr($config['subdirs'][$key], 0, 1) !== "/") { if (!empty($tmp['subdirs'][$key])) {
$path = $config['subdirs'][$value['path']].'/'.$config['subdirs'][$key]; if (substr($tmp['subdirs'][$key], 0, 1) !== "/") {
$config['subdirs'][$key] = $path; if (is_array($tmp['subdirs'][$value['path']])) {
$path = $tmp['subdirs'][$value['path']]['path'].'/'.$tmp['subdirs'][$key];
} else {
$path = $tmp['subdirs'][$value['path']].'/'.$tmp['subdirs'][$key];
} }
} }
} $config['subdirs'][$key] = array('path' => $path, 'strip' => $value['strip']);
foreach ($tree_base as $key => $value) {
if (!empty($config['subdirs'][$key])) {
$config['subdirs'][$key] = array('path' => $config['subdirs'][$key], 'strip' => $value['strip']);
} }
} }

View File

@@ -56,7 +56,7 @@ class Resolver {
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) { foreach ($iterator as $file) {
if ($file->isFile()) { if ($file->isFile()) {
if ($value['strip'] === 1) { if ($value['strip']) {
$this->addFile($file->getFileName(), $file->getPathname()); $this->addFile($file->getFileName(), $file->getPathname());
} else { } else {
$subdir = basename(dirname($file->getPathname())); $subdir = basename(dirname($file->getPathname()));