<?php
namespace gnomephp;
/**
* Configuation class.
* It can get configuraiton files like YAML, parse them , and then you can get config values from the file.
*
* @author peec
*
*/
class Configuration{
static private $configs=array();
/**
*
* Gets a configuration value from the config directory.
* E.g. you can create a file in the application/config folder named $file and get it with.
*
* Config file must be in YAML format.
*
* @param string $file name of file ( without .yml extension ).
* @param string $key ( If you want you can access a specific key.
* @throws ConfigurationException
*/
static public function get($file, $key=null, $suffix='.yml'){
// If app constant is not set, return null.
if (@constant('GNOME_APP_PATH') === null)return null;
// Only include these once. There for we create a cache in self::$configs.
if (!isset(self::$configs[$file])){
$path = GNOME_APP_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $file . $suffix;
if (!file_exists($path))throw new ConfigurationException("Tried to access config file $file. File location: $path");
self::$configs[$file] = \gnomephp\yaml\sfYaml::load($path);
}
if ($key===null && isset(self::$configs[$file]))return self::$configs[$file];
if ($key !== null && isset(self::$configs[$file][$key])) return self::$configs[$file][$key];
}
}