{% else-1 %}

                        
class Ini {

private $path;



function __construct($path) {

if (!is_dir($path))

die("нет папки {$path}");

$this->path = $path;

}

private function checkExtension($file) {

return pathinfo($file, PATHINFO_EXTENSION) == 'ini' ? true : false;

}



public function read(string $file, $section = null) {

if (!is_file($path.$file) or !$this->checkExtension($file))

die('файла нет');

$contents = parse_ini_file($this->path.$file, true);

if (!is_null($section) and !empty($contents[$section])) {

return $this->parse($contents[$section]);

}

$val = array();

foreach($contents as $section => $array) {

$val[$section] = $this->parse($array);

}

return $val;

}



private function parse(array $array) {

$values = array();

foreach($array as $key => $val) {

if ($val === '1') {

$val = true;

}

else if ($val === '') {

$val = false;

}

$values[$key] = $val;

}

return $values;

}

}
0 10 0
Без комментариев...