-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSettings.php
163 lines (156 loc) · 4.84 KB
/
Settings.php
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace Flipside;
/**
* Settings class
*
* This file describes the Settings Singleton
*
* PHP version 5 and 7
*
* @author Patrick Boyd / problem@burningflipside.com
* @copyright Copyright (c) 2017, Austin Artistic Reconstruction
* @license http://www.apache.org/licenses/ Apache 2.0 License
*/
/**
* A Singleton class to abstract access to various settings
*
* This class is the primary method to access sensative information such as DB logins
*/
class Settings extends \Flipside\Singleton
{
/**
* Load the settings file
*
* @see \Singleton::getInstance()
*/
protected function __construct()
{
if(isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
{
require $GLOBALS['FLIPSIDE_SETTINGS_LOC'].'/class.FlipsideSettings.php';
return;
}
if(file_exists('/var/www/secure_settings/class.FlipsideSettings.php'))
{
require '/var/www/secure_settings/class.FlipsideSettings.php';
return;
}
}
/**
* Instantiate all classes pointed to by the specified property name and return
*
* @param string $propName The property name in the settings file
*
* @return array An array of classes or empty array if not set
*/
public function getClassesByPropName($propName)
{
$ret = array();
if(isset(\FlipsideSettings::$$propName))
{
$prop = \FlipsideSettings::$$propName;
$keys = array_keys($prop);
$count = count($keys);
for($i = 0; $i < $count; $i++)
{
$class = $keys[$i];
array_push($ret, new $class($prop[$keys[$i]]));
}
}
return $ret;
}
/**
* Get the \Data\DataSet parameters by name
*
* @param string $dataSetName The name of the dataset
*
* @return array|false An array of properties or false if no such dataset
*/
public function getDataSetData($dataSetName)
{
if(!isset(\FlipsideSettings::$dataset) || !isset(\FlipsideSettings::$dataset[$dataSetName]))
{
return false;
}
return \FlipsideSettings::$dataset[$dataSetName];
}
/**
* Get the property from the settings file
*
* @param string $propName The name of the property in the settings file
* @param mixed $default The default value to return if not set
*
* @return mixed The value from the settings file or the value of $default it not set
*/
public function getGlobalSetting($propName, $default = false)
{
if(isset(\FlipsideSettings::$global) && isset(\FlipsideSettings::$global[$propName]))
{
return \FlipsideSettings::$global[$propName];
}
return $default;
}
/**
* Get the site links for the left hand side of the header
*
* @return array The array of links or an empty array if not set
*/
public function getSiteLinks()
{
if(isset(\FlipsideSettings::$sites))
{
return \FlipsideSettings::$sites;
}
return array();
}
/**
* Get the ldap connection string specified in the settings file
*
* @param mixed $default The default value to return if not set
*
* @return mixed The LDAP connection string or $default if not set
*/
private function getLDAPHost($default)
{
if(!isset(\FlipsideSettings::$ldap) || !isset(\FlipsideSettings::$ldap['host']))
{
return $default;
}
if(isset(\FlipsideSettings::$ldap['proto']))
{
return \FlipsideSettings::$ldap['proto'].'://'.\FlipsideSettings::$ldap['host'];
}
return \FlipsideSettings::$ldap['host'];
}
/**
* Get the specified ldap setting from the settings file
*
* @param string $propName The property name to retrieve
* @param boolean $ldapAuth Is the value authentication or other
* @param mixed $default The default value to return if not set
*
* @return mixed The value from the settings file
*/
public function getLDAPSetting($propName, $ldapAuth = false, $default = false)
{
switch($propName)
{
case 'host':
return $this->getLDAPHost($default);
default:
if($ldapAuth === false)
{
if(isset(\FlipsideSettings::$ldap) && isset(\FlipsideSettings::$ldap[$propName]))
{
return \FlipsideSettings::$ldap[$propName];
}
return $default;
}
if(isset(\FlipsideSettings::$ldap_auth) && isset(\FlipsideSettings::$ldap_auth[$propName]))
{
return \FlipsideSettings::$ldap_auth[$propName];
}
return $default;
}
}
}