Bearsampp 2026.3.26
API documentation
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
17class 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($bearsamppRoot->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 Util::logTrace('Replace config:');
90 $content = file_get_contents($bearsamppRoot->getConfigFilePath());
91 foreach ($params as $key => $value) {
92 $content = preg_replace('/^' . $key . '\s=\s.*/m', $key . ' = ' . '"' . $value.'"', $content, -1, $count);
93 Util::logTrace('## ' . $key . ': ' . $value . ' (' . $count . ' replacements done)');
94 $this->raw[$key] = $value;
95 }
96
97 file_put_contents($bearsamppRoot->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
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}
global $bearsamppRoot
const CFG_HOSTNAME
const CFG_LOGS_VERBOSE
const DISABLED
replaceAll($params)
const VERBOSE_REPORT
getMaxLogsArchives()
const CFG_ONLINE
const VERBOSE_SIMPLE
const CFG_TIMEZONE
getEnhancedQuickPick()
const CFG_NOTEPAD
const CFG_SCRIPTS_TIMEOUT
isLaunchStartup()
const CFG_BROWSER
const CFG_ENHANCED_QUICKPICK
const VERBOSE_TRACE
replace($key, $value)
const DOWNLOAD_ID
const ENABLED
const CFG_LANG
const CFG_MAX_LOGS_ARCHIVES
getScriptsTimeout()
const CFG_DEFAULT_LANG
const VERBOSE_DEBUG
validateEnhancedQuickPick()
const CFG_LAUNCH_STARTUP
getRaw($key)
const CFG_INCLUDE_PR
static logTrace($data, $file=null)