Add fromFile factory method to GitList\Config

This commit is contained in:
Christian Schorn
2012-10-31 18:03:42 +01:00
parent 32efd89781
commit 87d6391ba4
2 changed files with 8 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
<?php
// Load configuration
$config = new GitList\Config('config.ini');
$config = GitList\Config::fromFile('config.ini');
$config->set('git', 'repositories', rtrim($config->get('git', 'repositories'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
// Startup and configure Silex application

View File

@@ -6,13 +6,17 @@ class Config
{
protected $data;
public function __construct($file)
{
public static function fromFile($file) {
if (!file_exists($file)) {
die(sprintf('Please, create the %1$s file.', $file));
}
$data = parse_ini_file($file, true);
return new static($data);
}
$this->data = parse_ini_file($file, true);
public function __construct($data)
{
$this->data = $data;
$this->validateOptions();
}