Created by
Dmitriy Kuts
| <?php
namespace CodeRichard\Config;
use CodeRichard\Error\EnvironmentNotFoundException;
class Config
{
private static $loaded = false;
private static $configEntries = [];
public static function load($environment)
{
$base = __DIR__.'/../../config/';
$configFile = $base.$environment.'.php';
if(!file_exists($configFile))
{
throw new EnvironmentNotFoundException($environment);
}
if(!self::$loaded)
{
self::$configEntries = require $configFile;
}
}
public static function get($path, $default = '')
{
$arr = self::$configEntries;
$parts = explode('.', $path);
foreach($parts as $part)
{
if(isset($arr[$part]))
{
$arr = $arr[$part];
}
else
{
return $default;
}
}
return $arr;
}
}
|