Bearsampp
2026.7.11
Toggle main menu visibility
Loading...
Searching...
No Matches
class.config.php
Go to the documentation of this file.
1
<?php
2
/*
3
*
4
* * Copyright (c) 2022-2025 Bearsampp
5
* * License: GNU General Public License version 3 or later; see LICENSE.txt
6
* * Website: https://bearsampp.com
7
* * Github: https://github.com/Bearsampp
8
*
9
*/
10
17
class
Config
18
{
19
const
CFG_MAX_LOGS_ARCHIVES
=
'maxLogsArchives'
;
20
const
CFG_LOGS_VERBOSE
=
'logsVerbose'
;
21
const
CFG_LANG
=
'lang'
;
22
const
CFG_TIMEZONE
=
'timezone'
;
23
const
CFG_NOTEPAD
=
'notepad'
;
24
const
CFG_SCRIPTS_TIMEOUT
=
'scriptsTimeout'
;
25
const
DOWNLOAD_ID
=
'DownloadId'
;
26
27
const
CFG_INCLUDE_PR
=
'IncludePR'
;
28
const
CFG_ENHANCED_QUICKPICK
=
'EnhancedQuickPick'
;
29
const
CFG_DEFAULT_LANG
=
'defaultLang'
;
30
const
CFG_HOSTNAME
=
'hostname'
;
31
const
CFG_BROWSER
=
'browser'
;
32
const
CFG_ONLINE
=
'online'
;
33
const
CFG_LAUNCH_STARTUP
=
'launchStartup'
;
34
35
const
ENABLED
= 1;
36
const
DISABLED
= 0;
37
38
const
VERBOSE_SIMPLE
= 0;
39
const
VERBOSE_REPORT
= 1;
40
const
VERBOSE_DEBUG
= 2;
41
const
VERBOSE_TRACE
= 3;
42
43
private
$raw
;
44
49
public
function
__construct
()
50
{
51
global
$bearsamppRoot
;
52
53
// Set current timezone to match whats in .conf
54
$this->raw = parse_ini_file(
Path::getConfigFilePath
());
55
date_default_timezone_set($this->
getTimezone
());
56
}
57
64
public
function
getRaw
($key)
65
{
66
return
$this->raw[$key];
67
}
68
75
public
function
replace
($key, $value)
76
{
77
$this->
replaceAll
(array($key => $value));
78
}
79
85
public
function
replaceAll
($params)
86
{
87
global
$bearsamppRoot
;
88
89
Log::trace
(
'Replace config:'
);
90
$content = file_get_contents(
Path::getConfigFilePath
());
91
foreach
($params as $key => $value) {
92
$content = preg_replace(
'/^'
. $key .
'\s=\s.*/m'
, $key .
' = '
.
'"'
. $value.
'"'
, $content, -1, $count);
93
Log::trace
(
'## '
. $key .
': '
. $value .
' ('
. $count .
' replacements done)'
);
94
$this->raw[$key] = $value;
95
}
96
97
file_put_contents(
Path::getConfigFilePath
(), $content);
98
}
99
105
public
function
getLang
()
106
{
107
return
$this->raw[self::CFG_LANG];
108
}
109
115
public
function
getDefaultLang
()
116
{
117
return
$this->raw[self::CFG_DEFAULT_LANG];
118
}
119
125
public
function
getTimezone
()
126
{
127
return
$this->raw[self::CFG_TIMEZONE];
128
}
129
135
public
function
getDownloadId
()
136
{
137
return
$this->raw[self::DOWNLOAD_ID];
138
}
139
145
public
function
isOnline
()
146
{
147
return
$this->raw[self::CFG_ONLINE] == self::ENABLED;
148
}
149
155
public
function
isLaunchStartup
()
156
{
157
return
$this->raw[self::CFG_LAUNCH_STARTUP] == self::ENABLED;
158
}
159
165
public
function
getBrowser
()
166
{
167
return
$this->raw[self::CFG_BROWSER];
168
}
169
175
public
function
getHostname
()
176
{
177
return
$this->raw[self::CFG_HOSTNAME];
178
}
179
185
public
function
getScriptsTimeout
()
186
{
187
return
intval($this->raw[self::CFG_SCRIPTS_TIMEOUT]);
188
}
189
195
public
function
getNotepad
()
196
{
197
return
$this->raw[self::CFG_NOTEPAD];
198
}
199
205
public
function
getLogsVerbose
()
206
{
207
return
intval($this->raw[self::CFG_LOGS_VERBOSE]);
208
}
209
215
public
function
getMaxLogsArchives
()
216
{
217
return
intval($this->raw[self::CFG_MAX_LOGS_ARCHIVES]);
218
}
219
225
public
function
getIncludePr
()
226
{
227
return
isset($this->raw[self::CFG_INCLUDE_PR]) ? intval($this->raw[self::CFG_INCLUDE_PR]) : 0;
228
}
229
235
public
function
getEnhancedQuickPick
()
236
{
237
return
isset($this->raw[self::CFG_ENHANCED_QUICKPICK]) ? intval($this->raw[self::CFG_ENHANCED_QUICKPICK]) : 0;
238
}
239
245
public
function
validateEnhancedQuickPick
()
246
{
247
// Check if the parameter exists in the config
248
if
(!isset($this->raw[self::CFG_ENHANCED_QUICKPICK])) {
249
return
[
250
'valid'
=>
false
,
251
'error'
=>
'Missing parameter: EnhancedQuickPick is not defined in bearsampp.conf'
252
];
253
}
254
255
$value = $this->raw[self::CFG_ENHANCED_QUICKPICK];
256
257
// Check if the value is either "0" or "1"
258
if
($value !==
"0"
&& $value !==
"1"
) {
259
return
[
260
'valid'
=>
false
,
261
'error'
=>
'Invalid parameter: EnhancedQuickPick must be set to "0" or "1" in bearsampp.conf'
262
];
263
}
264
265
return
[
'valid'
=>
true
];
266
}
267
}
268
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
Config
Definition
class.config.php:18
Config\CFG_HOSTNAME
const CFG_HOSTNAME
Definition
class.config.php:30
Config\__construct
__construct()
Definition
class.config.php:49
Config\CFG_LOGS_VERBOSE
const CFG_LOGS_VERBOSE
Definition
class.config.php:20
Config\isOnline
isOnline()
Definition
class.config.php:145
Config\getTimezone
getTimezone()
Definition
class.config.php:125
Config\DISABLED
const DISABLED
Definition
class.config.php:36
Config\replaceAll
replaceAll($params)
Definition
class.config.php:85
Config\VERBOSE_REPORT
const VERBOSE_REPORT
Definition
class.config.php:39
Config\getMaxLogsArchives
getMaxLogsArchives()
Definition
class.config.php:215
Config\CFG_ONLINE
const CFG_ONLINE
Definition
class.config.php:32
Config\getNotepad
getNotepad()
Definition
class.config.php:195
Config\VERBOSE_SIMPLE
const VERBOSE_SIMPLE
Definition
class.config.php:38
Config\CFG_TIMEZONE
const CFG_TIMEZONE
Definition
class.config.php:22
Config\getHostname
getHostname()
Definition
class.config.php:175
Config\getEnhancedQuickPick
getEnhancedQuickPick()
Definition
class.config.php:235
Config\CFG_NOTEPAD
const CFG_NOTEPAD
Definition
class.config.php:23
Config\getDefaultLang
getDefaultLang()
Definition
class.config.php:115
Config\CFG_SCRIPTS_TIMEOUT
const CFG_SCRIPTS_TIMEOUT
Definition
class.config.php:24
Config\getBrowser
getBrowser()
Definition
class.config.php:165
Config\isLaunchStartup
isLaunchStartup()
Definition
class.config.php:155
Config\CFG_BROWSER
const CFG_BROWSER
Definition
class.config.php:31
Config\CFG_ENHANCED_QUICKPICK
const CFG_ENHANCED_QUICKPICK
Definition
class.config.php:28
Config\getDownloadId
getDownloadId()
Definition
class.config.php:135
Config\VERBOSE_TRACE
const VERBOSE_TRACE
Definition
class.config.php:41
Config\replace
replace($key, $value)
Definition
class.config.php:75
Config\DOWNLOAD_ID
const DOWNLOAD_ID
Definition
class.config.php:25
Config\getLang
getLang()
Definition
class.config.php:105
Config\ENABLED
const ENABLED
Definition
class.config.php:35
Config\getLogsVerbose
getLogsVerbose()
Definition
class.config.php:205
Config\CFG_LANG
const CFG_LANG
Definition
class.config.php:21
Config\CFG_MAX_LOGS_ARCHIVES
const CFG_MAX_LOGS_ARCHIVES
Definition
class.config.php:19
Config\getIncludePr
getIncludePr()
Definition
class.config.php:225
Config\$raw
$raw
Definition
class.config.php:43
Config\getScriptsTimeout
getScriptsTimeout()
Definition
class.config.php:185
Config\CFG_DEFAULT_LANG
const CFG_DEFAULT_LANG
Definition
class.config.php:29
Config\VERBOSE_DEBUG
const VERBOSE_DEBUG
Definition
class.config.php:40
Config\validateEnhancedQuickPick
validateEnhancedQuickPick()
Definition
class.config.php:245
Config\CFG_LAUNCH_STARTUP
const CFG_LAUNCH_STARTUP
Definition
class.config.php:33
Config\getRaw
getRaw($key)
Definition
class.config.php:64
Config\CFG_INCLUDE_PR
const CFG_INCLUDE_PR
Definition
class.config.php:27
Log\trace
static trace($data, $file=null)
Definition
class.log.php:605
Path\getConfigFilePath
static getConfigFilePath($aetrayPath=false)
Definition
class.path.php:375
sandbox
core
classes
class.config.php
Generated by
1.17.0