Arlevnar
Новичок
Доброго времени суток. Речь идёт о велосипеде.
Создал класс для работы с конфигурационными файлами. И хотел бы узнать что думают спецы о такой конструкции.
Создал класс для работы с конфигурационными файлами. И хотел бы узнать что думают спецы о такой конструкции.
PHP:
<?php
class Config {
/**
* Path to configuration files
*
* @var str
*/
private $path;
/**
* Extending the configuration files
*
* @var str
*/
private $ext;
public function __construct($dirpath, $ext='.php')
{
$this->path = $dirpath;
$this->ext = $ext;
return $this;
}
public function set_path($dirpath)
{
$this->path = $dirpath;
}
private function parse($str)
{
$result['path'] = $this->path.substr($str, 0, strpos($str, '.', 0)).$this->ext;
$result['keys'] = '[\''.str_replace('.','\'][\'',substr($str, strpos($str, '.', 0) + 1)).'\']';
return $result;
}
public function get($path)
{
$var = $this->parse($path);
if (!file_exists($var['path'])) {
throw new Exception("Файл `".$var['path']."` не найден");
}
$data = (array) include($var['path']);
if (!is_array($data)) {
throw new Exception("Данные не найдены");
}
eval('$is = isset($data'.$var['keys'].');');
if (!$is) {
throw new Exception("Данные не найдены");
}
eval('$result = $data'.$var['keys'].';');
return $result;
}
}