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

class.Settings.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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($this->methods, new $class($prop[$keys[$i]]));
0 ignored issues
show
The property methods does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
84
                {
85
                    return FlipsideSettings::$ldap[$propName];
86
                }
87
                return FlipsideSettings::$ldap_auth[$propName];
88
        }
89
    }
90
}
91