aboutsummaryrefslogtreecommitdiff
path: root/src/bdrem/Config.php
blob: 5d34f7607fe25409c2b4059a7a9ac3319cf5d89c (plain)
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
<?php
namespace bdrem;

class Config
{
    public $source;
    public $daysBefore;
    public $daysAfter;
    public $locale;

    public function load()
    {
        $f = __DIR__ . '/../../data/bdrem.config.php';
        if (file_exists($f)) {
            return $this->loadFile($f);
        }

        throw new \Exception('No config file found');
    }

    protected function loadFile($filename)
    {
        include $filename;
        $this->source = $source;
        $this->daysBefore = $daysBefore;
        $this->daysAfter = $daysAfter;
        if (isset($locale)) {
            $this->locale = $locale;
        }
    }

    public function loadSource()
    {
        if ($this->source === null) {
            throw new \Exception('No source defined');
        }

        $settings = $this->source;
        $class = '\\bdrem\\Source_' . array_shift($settings);

        return new $class($settings[0]);
    }
}
?>