Added method array_replace_recursive() & recurse() to the installer which corrects issue #30 see https://git.n64.cc/nosial/ncc/-/issues/30
Updated some default values for ncc.yaml for better security.
This commit is contained in:
parent
e4e0c7b9b5
commit
6371f26046
2 changed files with 58 additions and 22 deletions
|
@ -23,9 +23,6 @@ php:
|
|||
# Whether to initialize NCC when running `require('ncc');`
|
||||
initialize_on_require: true
|
||||
|
||||
# if NCC should handle fatal exceptions during execution
|
||||
handle_exceptions: true
|
||||
|
||||
git:
|
||||
# if git is enabled or not
|
||||
enabled: true
|
||||
|
@ -55,10 +52,10 @@ composer:
|
|||
quiet: false
|
||||
|
||||
# Disable ANSI output
|
||||
no_ansi: false
|
||||
no_ansi: true
|
||||
|
||||
# Do not ask any interactive question
|
||||
no_interaction: false
|
||||
no_interaction: true
|
||||
|
||||
# Display timing and memory usage information
|
||||
profile: false
|
||||
|
|
|
@ -712,7 +712,6 @@
|
|||
$config_obj['composer']['enable_internal_composer'] = false;
|
||||
if($config_obj['composer']['executable_path'] == null)
|
||||
{
|
||||
// TODO: Implement Configuration Tools
|
||||
Console::outWarning('Cannot locate the executable path for \'composer\', run \'ncc config --composer.executable_path="composer.phar"\' as root to update the path');
|
||||
}
|
||||
}
|
||||
|
@ -724,7 +723,7 @@
|
|||
{
|
||||
if ($NCC_FILESYSTEM->exists(PathFinder::getConfigurationFile()))
|
||||
{
|
||||
$config_backup = IO::fread(PathFinder::getConfigurationFile());
|
||||
$config_backup = Yaml::parseFile(PathFinder::getConfigurationFile());
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
|
@ -736,33 +735,73 @@
|
|||
// Create/Update configuration file
|
||||
$config_obj = Yaml::parseFile(__DIR__ . DIRECTORY_SEPARATOR . 'default_config.yaml');
|
||||
|
||||
// Update the old configuration
|
||||
if(!function_exists('array_replace_recursive'))
|
||||
{
|
||||
/**
|
||||
* @param $array
|
||||
* @param $array1
|
||||
* @return array|mixed
|
||||
* @author <msahagian@dotink.org>
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
*/
|
||||
function array_replace_recursive($array, $array1)
|
||||
{
|
||||
// handle the arguments, merge one by one
|
||||
$args = func_get_args();
|
||||
$array = $args[0];
|
||||
if (!is_array($array))
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
for ($i = 1; $i < count($args); $i++)
|
||||
{
|
||||
if (is_array($args[$i]))
|
||||
{
|
||||
$array = recurse($array, $args[$i]);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('recurse'))
|
||||
{
|
||||
/**
|
||||
* @param $array
|
||||
* @param $array1
|
||||
* @return mixed
|
||||
* @author <msahagian@dotink.org>
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
*/
|
||||
function recurse($array, $array1)
|
||||
{
|
||||
foreach ($array1 as $key => $value)
|
||||
{
|
||||
// create new key in $array, if it is empty or not an array
|
||||
/** @noinspection PhpConditionAlreadyCheckedInspection */
|
||||
if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key])))
|
||||
{
|
||||
$array[$key] = array();
|
||||
}
|
||||
|
||||
// overwrite the value in the base array
|
||||
if (is_array($value))
|
||||
{
|
||||
$value = recurse($array[$key], $value);
|
||||
}
|
||||
$array[$key] = $value;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($config_backup !== null)
|
||||
{
|
||||
$old_config_obj = Yaml::parse($config_backup);
|
||||
foreach($old_config_obj as $section => $value)
|
||||
{
|
||||
if(isset($config_obj[$section]))
|
||||
{
|
||||
foreach($value as $section_item => $section_value)
|
||||
{
|
||||
if(!isset($config_obj[$section][$section_item]))
|
||||
{
|
||||
$config_obj[$section][$section_item] = $section_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$config_obj[$section] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$config_obj = array_replace_recursive($config_obj, $config_backup);
|
||||
|
||||
if($config_backup == null)
|
||||
{
|
||||
Console::out('Generating ncc.yaml');
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue