public function save($allowed = array())
{
// Aggregating files array from changed keys
$aggr = array();
foreach ($this->changed_keys as $key => $value) {
array_set($aggr, $key, $value);
}
// $allow_in_cli = array('database', 'microweber');
// Preparing data
foreach ($aggr as $file => $items) {
$path = $this->app->configPath() . '/' . $this->app->environment() . '/';
if (!is_dir($path)) {
$path = $this->app->configPath() . '/';
}
$to_save = true;
if (is_string($allowed)) {
$allowed = explode(',', $allowed);
}
if (is_array($allowed)) {
if (!empty($allowed)) {
if (!in_array($file, $allowed) and !array_search($file, $allowed)) {
$to_save = false;
}
}
}
if ($to_save) {
if (!file_exists($path)) {
File::makeDirectory($path);
}
$path .= $file . '.php';
$val = var_export($this->items[$file], true);
if (is_string($val)) {
$temp = str_replace('\\', '\\\\', storage_path());
$val = str_replace("'" . $temp . '\\\\', "storage_path().DIRECTORY_SEPARATOR.'", $val);
$val = str_replace("'" . storage_path() . DIRECTORY_SEPARATOR, "storage_path().DIRECTORY_SEPARATOR.'", $val);
$val = str_replace("'" . $val, "storage_path().'", $val);
$val = str_replace('\\', DIRECTORY_SEPARATOR, $val);
$code = '<?php return ' . $val . ';';
} else {
$code = $val;
}
// Storing data
File::put($path, $code);
}
}
}