diff options
author | Fbenas <philbeansburton@gmail.com> | 2018-02-18 22:29:36 +0000 |
---|---|---|
committer | Fbenas <philbeansburton@gmail.com> | 2018-02-18 22:29:36 +0000 |
commit | 62146c4027e48cfbdb4f518de137de8430392e24 (patch) | |
tree | 791efd0bdccf4f23302428539a0fdc1047502646 /src/Config | |
parent | 7d2128f364c0e81a15653db2508d3e09b262eca1 (diff) |
Split client and manager
Diffstat (limited to 'src/Config')
-rw-r--r-- | src/Config/Loader.php | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/src/Config/Loader.php b/src/Config/Loader.php deleted file mode 100644 index 97df62e..0000000 --- a/src/Config/Loader.php +++ /dev/null @@ -1,150 +0,0 @@ -<?php - -namespace App\Config; - -/** - * A class to load a config into an array - * Throws an exception if it fails to laod - * - * @author Phil Burton <phil@pgburton.com> - */ -class Loader -{ - /** - * A loaded config array - * - * @var mixed[] - */ - protected $config; - - /** - * Try and load a config - * - * @author Phil Burton <phil@pgburton.com> - */ - public function __construct() - { - foreach ($this->getConfigPaths() as $path) { - if ($config = $this->loadConfig($path)) { - $this->validate(); - $this->clean(); - return; - } - } - - // No config found - throw new \Exception('Could not find config file.'); - } - - /** - * Try and load a config file - * If we can't return false - * - * @author Phil Burton <phil@pgburton.com> - * @return mixed[]|false - */ - public function loadConfig(string $path) - { - $filename = $path . '/' . $this->getConfigFilename(); - - if (!$this->config) { - if (!file_exists($filename)) { - return false; - } - - if (!is_readable($filename)) { - return false; - } - - if (!$config = include($filename)) { - return false; - } - - $this->config = $config; - } - - return $this->config; - } - - /** - * Return the nsam of the config file to load - * - * @author Phil Burton <phil@pgburton.com> - * @return string; - */ - public function getConfigFilename() - { - return 'dipper.php'; - } - - /** - * Make sure the config is up to scratch - * - * @author Phil Burton <phil@pgburton.com> - */ - public function validate() - { - $config = $this->getConfig(); - - foreach ($this->getRequired() as $required) { - if (!isset($config[$required])) { - throw new \Exception("Could not find " . $required . " in config file."); - } - } - } - - /** - * Clean up the config ready for use - * - * @author Phil Burton <phil@pgburton.com> - */ - public function clean() - { - $config = $this->getConfig(); - foreach ($config as &$item) { - // Remove trailing slashes - $item = rtrim($item, "/"); - } - - $this->config = $config; - } - - /** - * Return the array of config paths - * - * @author Phil Burton <phil@pgburton.com> - * @return string[] - */ - public function getConfigPaths() - { - return [ - realpath(dirname(__FILE__) . "/../../"), // Root of dipper - realpath(dirname(__FILE__) . "/../../config") // Config directory in dipper - ]; - } - - /** - * Return the loaded config - * - * @author Phil Burton <phil@pgburton.com> - * @return mixed[] - */ - public function getConfig() - { - return $this->config; - } - - /** - * Return the required config keys - * - * @author Phil Burton <phil@pgburton.com> - * @return string[] - */ - public function getRequired() - { - return [ - "SITES_ROOT", - "CONFIG_ROOT" - ]; - } -} |