Completed
Pull Request — master (#11)
by Patrick
03:26
created

Settings::getClassesByPropName()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 16
rs 9.4285
1
<?php
2
3
class Settings extends \Singleton
4
{
5
    protected function __construct()
6
    {
7
        if(isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
8
        {
9
            require $GLOBALS['FLIPSIDE_SETTINGS_LOC'].'/class.FlipsideSettings.php';
10
            return;
11
        }
12
        if(is_readable('/var/www/secure_settings/class.FlipsideSettings.php'))
13
        {
14
            require '/var/www/secure_settings/class.FlipsideSettings.php';
15
            return;
16
        }
17
    }
18
19
    public function getClassesByPropName($propName)
20
    {
21
        $ret = array();
22
        if(isset(FlipsideSettings::$$propName))
23
        {
24
            $prop = FlipsideSettings::$$propName;
25
            $keys = array_keys($prop);
26
            $count = count($keys);
27
            for($i = 0; $i < $count; $i++)
28
            {
29
                $class = $keys[$i];
30
                array_push($ret, new $class($prop[$keys[$i]]));
31
            }
32
        }
33
        return $ret;
34
    }
35
36
    public function getDataSetData($dataSetName)
37
    {
38
        if(!isset(FlipsideSettings::$dataset) || !isset(FlipsideSettings::$dataset[$dataSetName]))
39
        {
40
            return false;
41
        }
42
        return FlipsideSettings::$dataset[$dataSetName];
43
    }
44
45
    public function getGlobalSetting($propName, $default = false)
46
    {
47
        if(isset(FlipsideSettings::$global) && FlipsideSettings::$global[$propName])
48
        {
49
            return FlipsideSettings::$global[$propName];
50
        }
51
        return $default;
52
    }
53
54
    public function getSiteLinks()
55
    {
56
        if(isset(FlipsideSettings::$sites))
57
        {
58
            return FlipsideSettings::$sites;
59
        }
60
        return array();
61
    }
62
63
    private function getLDAPHost($default)
64
    {
65
        if(!isset(FlipsideSettings::$ldap) || !isset(FlipsideSettings::$ldap['host']))
66
        {
67
            return $default;
68
        }
69
        if(isset(\FlipsideSettings::$ldap['proto']))
70
        {
71
            return \FlipsideSettings::$ldap['proto'].'://'.\FlipsideSettings::$ldap['host'];
72
        }
73
        return \FlipsideSettings::$ldap['host'];
74
    }
75
76
    public function getLDAPSetting(string $propName, $ldapAuth = false, $default = false)
77
    {
78
        switch($propName)
79
        {
80
            case 'host':
81
                return $this->getLDAPHost($default);
82
            default:
83
                if($ldapAuth === false)
84
                {
85
                    return FlipsideSettings::$ldap[$propName];
86
                }
87
                return FlipsideSettings::$ldap_auth[$propName];
88
        }
89
    }
90
}
91