This repository was archived by the owner on Apr 28, 2024. It is now read-only.
forked from klaussilveira/gitlist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.php
More file actions
78 lines (60 loc) · 1.72 KB
/
Config.php
File metadata and controls
78 lines (60 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace GitList;
class Config
{
protected $data;
public static function fromFile($file)
{
if (!file_exists($file)) {
die(sprintf('Please, create the %1$s file.', $file));
}
$data = parse_ini_file($file, true);
$config = new static($data);
$config->validateOptions();
return $config;
}
public function __construct($data = array())
{
$this->data = $data;
}
public function get($section, $option)
{
if (!array_key_exists($section, $this->data)) {
return false;
}
if (!array_key_exists($option, $this->data[$section])) {
return false;
}
return $this->data[$section][$option];
}
public function getSection($section)
{
if (!array_key_exists($section, $this->data)) {
return false;
}
return $this->data[$section];
}
public function set($section, $option, $value)
{
$this->data[$section][$option] = $value;
}
protected function validateOptions()
{
$repositories = $this->get('git', 'repositories');
$atLeastOneOk = false;
$atLeastOneWrong = false;
foreach ($repositories as $directory) {
if (!$directory || !is_dir($directory)) {
$atLeastOneWrong = true;
} else {
$atLeastOneOk = true;
}
}
if (!$atLeastOneOk) {
die("Please, edit the config file and provide your repositories directory");
}
if ($atLeastOneWrong) {
die("One or more of the supplied repository paths appears to be wrong. Please, check the config file");
}
}
}