class AF_Config
{
protected $data = array();
public function __construct(array $data)
{
$data = array_merge($data, $this->data);
foreach ($data as $key => $value)
{
if (is_array($value))
{
$this->data[$key] = new self($value);
}
else
{
$this->data[$key] = $value;
}
}
return true;
}
public function get($name, $default = null)
{
if (array_key_exists($name, $this->data))
{
$result = $this->data[$name];
}
elseif (isset($default))
{
$result = $default;
}
else
{
require_once 'AF/Exception.php';
twrow new AF_Exception('Key "' . $name . '" does not exists in data array');
}
return $result;
}
public function __get($name)
{
return $this->get($name);
}
public function toArray()
{
$array = array();
foreach ($this->data as $key => $value)
{
if ($value instanceof AF_Config)
{
$array[$key] = $value->toArray();
}
else
{
$array[$key] = $value;
}
}
return $array;
}
public function __isset($name)
{
return isset($this->data[$name]);
}
}
чтобы вызывать данные из data таким макаром:
Config::getInstance()->hello->world->test->bla;