forked from PHPAuth/PHPAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.php
139 lines (112 loc) · 3.17 KB
/
Config.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
<?php
namespace PHPAuth;
/**
* PHPAuth Config class
*/
class Config
{
protected $dbh;
protected $config;
protected $config_table = 'config';
/**
*
* Config::__construct()
*
* @param \PDO $dbh
* @param string $config_table
*/
public function __construct(\PDO $dbh, $config_table = 'config')
{
$this->dbh = $dbh;
if (func_num_args() > 1) {
$this->config_table = $config_table;
}
$this->config = array();
$query = $this->dbh->query("SELECT * FROM {$this->config_table}");
$this->config = $query->fetchAll(\PDO::FETCH_KEY_PAIR);
$this->setForgottenDefaults(); // Danger foreseen is half avoided.
}
/**
* Config::__get()
*
* @param mixed $setting
* @return string
*/
public function __get($setting)
{
return $this->config[$setting];
}
/**
* @return array
*/
public function getAll()
{
return $this->config;
}
/**
* Config::__set()
*
* @param mixed $setting
* @param mixed $value
* @return bool
*/
public function __set($setting, $value)
{
$query = $this->dbh->prepare("UPDATE {$this->config_table} SET value = ? WHERE setting = ?");
if ($query->execute(array($value, $setting))) {
$this->config[$setting] = $value;
return true;
}
return false;
}
/**
* Config::override()
*
* @param mixed $setting
* @param mixed $value
* @return bool
*/
public function override($setting, $value)
{
$this->config[$setting] = $value;
return true;
}
/**
* Danger foreseen is half avoided.
*
* Set default values.
* REQUIRED FOR USERS THAT DOES NOT UPDATE THEIR `config` TABLES.
*/
protected function setForgottenDefaults()
{
// verify* values.
if (!isset($this->config['verify_password_min_length'])) {
$this->config['verify_password_min_length'] = 3;
}
if (!isset($this->config['verify_password_max_length'])) {
$this->config['verify_password_max_length'] = 150;
}
if (!isset($this->config['verify_password_strong_requirements'])) {
$this->config['verify_password_strong_requirements'] = 1;
}
if (!isset($this->config['verify_email_min_length'])) {
$this->config['verify_email_min_length'] = 5;
}
if (!isset($this->config['verify_email_max_length'])) {
$this->config['verify_email_max_length'] = 100;
}
if (!isset($this->config['verify_email_use_banlist'])) {
$this->config['verify_email_use_banlist'] = 1;
}
// emailmessage* values
if (!isset($this->config['emailmessage_suppress_activation'])) {
$this->config['emailmessage_suppress_activation'] = 0;
}
if (!isset($this->config['emailmessage_suppress_reset'])) {
$this->config['emailmessage_suppress_reset'] = 0;
}
if (!isset($this->config['mail_charset'])) {
$this->config['mail_charset'] = "UTF-8";
}
}
}