Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement