Bearsampp 2025.8.29
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_DEFAULT_LANG = 'defaultLang';
29 const CFG_HOSTNAME = 'hostname';
30 const CFG_BROWSER = 'browser';
31 const CFG_ONLINE = 'online';
32 const CFG_LAUNCH_STARTUP = 'launchStartup';
33
34 const ENABLED = 1;
35 const DISABLED = 0;
36
37 const VERBOSE_SIMPLE = 0;
38 const VERBOSE_REPORT = 1;
39 const VERBOSE_DEBUG = 2;
40 const VERBOSE_TRACE = 3;
41
42 private $raw;
43
48 public function __construct()
49 {
50 global $bearsamppRoot;
51
52 // Set current timezone to match whats in .conf
53 $this->raw = parse_ini_file($bearsamppRoot->getConfigFilePath());
54 date_default_timezone_set($this->getTimezone());
55 }
56
63 public function getRaw($key)
64 {
65 return $this->raw[$key];
66 }
67
74 public function replace($key, $value)
75 {
76 $this->replaceAll(array($key => $value));
77 }
78
84 public function replaceAll($params)
85 {
86 global $bearsamppRoot;
87
88 Util::logTrace('Replace config:');
89 $content = file_get_contents($bearsamppRoot->getConfigFilePath());
90 foreach ($params as $key => $value) {
91 $content = preg_replace('/^' . $key . '\s=\s.*/m', $key . ' = ' . '"' . $value.'"', $content, -1, $count);
92 Util::logTrace('## ' . $key . ': ' . $value . ' (' . $count . ' replacements done)');
93 $this->raw[$key] = $value;
94 }
95
96 file_put_contents($bearsamppRoot->getConfigFilePath(), $content);
97 }
98
104 public function getLang()
105 {
106 return $this->raw[self::CFG_LANG];
107 }
108
114 public function getDefaultLang()
115 {
116 return $this->raw[self::CFG_DEFAULT_LANG];
117 }
118
124 public function getTimezone()
125 {
126 return $this->raw[self::CFG_TIMEZONE];
127 }
128
134 public function getDownloadId()
135 {
136 return $this->raw[self::DOWNLOAD_ID];
137 }
138
144 public function isOnline()
145 {
146 return $this->raw[self::CFG_ONLINE] == self::ENABLED;
147 }
148
154 public function isLaunchStartup()
155 {
156 return $this->raw[self::CFG_LAUNCH_STARTUP] == self::ENABLED;
157 }
158
164 public function getBrowser()
165 {
166 return $this->raw[self::CFG_BROWSER];
167 }
168
174 public function getHostname()
175 {
176 return $this->raw[self::CFG_HOSTNAME];
177 }
178
184 public function getScriptsTimeout()
185 {
186 return intval($this->raw[self::CFG_SCRIPTS_TIMEOUT]);
187 }
188
194 public function getNotepad()
195 {
196 return $this->raw[self::CFG_NOTEPAD];
197 }
198
204 public function getLogsVerbose()
205 {
206 return intval($this->raw[self::CFG_LOGS_VERBOSE]);
207 }
208
214 public function getMaxLogsArchives()
215 {
216 return intval($this->raw[self::CFG_MAX_LOGS_ARCHIVES]);
217 }
218
224 public function getIncludePr()
225 {
226 return isset($this->raw[self::CFG_INCLUDE_PR]) ? intval($this->raw[self::CFG_INCLUDE_PR]) : 0;
227 }
228}
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
const CFG_NOTEPAD
const CFG_SCRIPTS_TIMEOUT
isLaunchStartup()
const CFG_BROWSER
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
const CFG_LAUNCH_STARTUP
getRaw($key)
const CFG_INCLUDE_PR
static logTrace($data, $file=null)