66 lines
1.1 KiB
PHP
66 lines
1.1 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Sleepy - a REST framework
|
||
|
*
|
||
|
*
|
||
|
* A PHP Rest Framework valuing convention over configuration,
|
||
|
* but aiming to be as flexible as possible
|
||
|
*
|
||
|
* @author Timothy J. Warren
|
||
|
*/
|
||
|
|
||
|
namespace Sleepy\Core;
|
||
|
|
||
|
/**
|
||
|
* Class for managing configuration values
|
||
|
*/
|
||
|
class Config {
|
||
|
|
||
|
/**
|
||
|
* The config array
|
||
|
* @var array
|
||
|
*/
|
||
|
protected $data = [];
|
||
|
|
||
|
/**
|
||
|
* Load the specified config file and return
|
||
|
* the config array
|
||
|
*
|
||
|
* @throws \InvalidArugmentException
|
||
|
* @param string $name
|
||
|
* @return array
|
||
|
*/
|
||
|
public function load($name)
|
||
|
{
|
||
|
$file = APPPATH . 'config/'. $name . '.php';
|
||
|
|
||
|
if (is_file($file))
|
||
|
{
|
||
|
$conf =require_once($file);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
throw new \InvalidArgumentException("The config file doesn't exist");
|
||
|
}
|
||
|
|
||
|
$this->data[$name] = $conf;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get the specific parameter from the specified file
|
||
|
*
|
||
|
* @param string $file
|
||
|
* @param string $key
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function get($file, $key=NULL)
|
||
|
{
|
||
|
if (is_null($key))
|
||
|
{
|
||
|
return $this->data[$file];
|
||
|
}
|
||
|
|
||
|
return $this->data[$file][$key];
|
||
|
}
|
||
|
}
|
||
|
// End of Core/Config.php
|