testing file config, pass

This commit is contained in:
Guillermo Dev
2018-10-11 01:40:58 +02:00
parent 40d96a8911
commit 97bdda2894
3 changed files with 51 additions and 10 deletions

Binary file not shown.

View File

@@ -8,6 +8,11 @@ class Configuration {
*/
private static $instance = null;
/**
* @var
*/
private static $customConfigFilePath;
/**
* ! WARNING !
*
@@ -23,8 +28,9 @@ class Configuration {
*/
private $values = array();
private $customConfigFilename = 'configuration.local.php';
/**
*
*/
private function __construct()
{
if (!isset($this->values['session'])) {
@@ -34,27 +40,47 @@ class Configuration {
if (!isset($this->values['session']['save_path'])) {
$this->values['session']['save_path'] = session_save_path();
}
if (file_exists(self::getConfigFilePath())) {
$this->loadConfigFromFile();
}
}
/**
* The path to the file including file name
* @param string $filePath
* @return void
*/
public static function setConfigFilePath($filePath)
{
if (!file_exists($filePath)) {
throw new \RuntimeException("The file path $filePath, does not exist");
}
self::$customConfigFilePath = $filePath;
}
/**
*
* @return String
*/
public function getCustomConfigFilePath()
public static function getConfigFilePath()
{
return realpath(dirname(__FILE__) . '/../../../../../config/') . $this->customConfigFilename;
if (null === self::$customConfigFilePath) {
self::$customConfigFilePath = realpath(dirname(__FILE__) . '/../../../../../config/configuration.local.php');
}
return self::$customConfigFilePath;
}
/**
* @return array
* @throws \RuntimeException
*/
public function getCustomConfigFromFile()
public function getConfigFromFile()
{
if (!file_exists($this->getCustomConfigFilePath())) {
throw new \RuntimeException("The file : {$this->getCustomConfigFilePath()} does not exist");
if (!file_exists(self::getConfigFilePath())) {
throw new \RuntimeException("The file : {self::getConfigFilePath()} does not exist");
}
return include $this->getCustomConfigFilePath();
return include self::getConfigFilePath();
}
/**
@@ -62,9 +88,9 @@ class Configuration {
* @return void
* @throws \RuntimeException
*/
public function loadCustomConfigFromFile()
public function loadConfigFromFile()
{
$this->setCustomConfig($this->getCustomConfigFromFile());
$this->setCustomConfig($this->getConfigFromFile());
}
/**