From 45ea34da943af1b174f1e0fabeab6f5bac8461a0 Mon Sep 17 00:00:00 2001 From: Aerex Date: Tue, 5 May 2020 00:04:31 -0500 Subject: [PATCH] fix: Created config directory recursively --- lib/Configs/ConfigBuilder.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/Configs/ConfigBuilder.php b/lib/Configs/ConfigBuilder.php index 05bfa8a..92a9638 100644 --- a/lib/Configs/ConfigBuilder.php +++ b/lib/Configs/ConfigBuilder.php @@ -9,13 +9,27 @@ use Symfony\Component\Yaml\Yaml; class ConfigBuilder implements ConfigurationInterface { private $configs = []; - private $configFile; + private $configDir; - public function __construct($configFile = '~/.config/baikal') { - $this->configFile = $configFile; + public function __construct($configDir = null) { + if (!isset($configDir)) { + $this->configDir = $this->getHomeDir() . '~/.config/baikal'; + } else { + $this->configDir = $configDir; + } $this->processor = new Processor(); } + private function getHomeDir() { + if (stristr(PHP_OS, 'WIN')) { + return rtrim($_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'], '\\/'); + } else { + return rtrim($_SERVER['HOME'], '/'); + } + + } + + public function add($config) { $this->configs[] = $config; } @@ -32,10 +46,10 @@ class ConfigBuilder implements ConfigurationInterface { } public function readContent() { - if (!is_dir($this->configFile)) { - mkdir($this->configFile); + if (!is_dir($this->configDir)) { + mkdir($this->configDir, 0755, true); } - $contents = sprintf('%s/storage.yml', $this->configFile); + $contents = sprintf('%s/storage.yml', $this->configDir); return file_get_contents($contents); }