2014-05-14 10:32:31 -04:00
|
|
|
<?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 = [];
|
2014-05-14 16:58:34 -04:00
|
|
|
|
2014-05-14 10:32:31 -04:00
|
|
|
/**
|
2014-05-14 16:58:34 -04:00
|
|
|
* Load the data into the class member
|
2014-05-14 10:32:31 -04:00
|
|
|
*/
|
2014-05-14 16:58:34 -04:00
|
|
|
public function __construct()
|
2014-05-14 10:32:31 -04:00
|
|
|
{
|
2014-05-14 16:58:34 -04:00
|
|
|
$conf_files = glob(APPPATH . 'config/*.php');
|
2014-05-14 10:32:31 -04:00
|
|
|
|
2014-05-14 16:58:34 -04:00
|
|
|
foreach($conf_files as $file)
|
2014-05-14 10:32:31 -04:00
|
|
|
{
|
2014-05-14 16:58:34 -04:00
|
|
|
$data = require_once($file);
|
|
|
|
|
|
|
|
$name = str_replace('.php', '', basename($file));
|
|
|
|
$this->data[$name] = $data;
|
2014-05-14 10:32:31 -04:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 16:58:34 -04:00
|
|
|
|
2014-05-14 10:32:31 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the specific parameter from the specified file
|
|
|
|
*
|
2014-05-14 16:58:34 -04:00
|
|
|
* @throws \InvalidArgumentException
|
2014-05-14 10:32:31 -04:00
|
|
|
* @param string $file
|
|
|
|
* @param string $key
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function get($file, $key=NULL)
|
|
|
|
{
|
2014-05-14 16:58:34 -04:00
|
|
|
if ( ! array_key_exists($file, $this->data))
|
2014-05-14 10:32:31 -04:00
|
|
|
{
|
2014-05-14 16:58:34 -04:00
|
|
|
throw new \InvalidArgumentException("The config file doesn't exist");
|
2014-05-14 10:32:31 -04:00
|
|
|
}
|
|
|
|
|
2014-05-14 16:58:34 -04:00
|
|
|
return (is_null($key))
|
|
|
|
? $this->data[$file]
|
|
|
|
: $this->data[$file][$key];
|
2014-05-14 10:32:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of Core/Config.php
|