Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
Config Class Reference

Public Member Functions

 __construct ()
 getBrowser ()
 getDefaultLang ()
 getDownloadId ()
 getEnhancedQuickPick ()
 getHostname ()
 getIncludePr ()
 getLang ()
 getLogsVerbose ()
 getMaxLogsArchives ()
 getNotepad ()
 getRaw ($key)
 getScriptsTimeout ()
 getTimezone ()
 isLaunchStartup ()
 isOnline ()
 replace ($key, $value)
 replaceAll ($params)
 validateEnhancedQuickPick ()

Data Fields

const CFG_BROWSER = 'browser'
const CFG_DEFAULT_LANG = 'defaultLang'
const CFG_ENHANCED_QUICKPICK = 'EnhancedQuickPick'
const CFG_HOSTNAME = 'hostname'
const CFG_INCLUDE_PR = 'IncludePR'
const CFG_LANG = 'lang'
const CFG_LAUNCH_STARTUP = 'launchStartup'
const CFG_LOGS_VERBOSE = 'logsVerbose'
const CFG_MAX_LOGS_ARCHIVES = 'maxLogsArchives'
const CFG_NOTEPAD = 'notepad'
const CFG_ONLINE = 'online'
const CFG_SCRIPTS_TIMEOUT = 'scriptsTimeout'
const CFG_TIMEZONE = 'timezone'
const DISABLED = 0
const DOWNLOAD_ID = 'DownloadId'
const ENABLED = 1
const VERBOSE_DEBUG = 2
const VERBOSE_REPORT = 1
const VERBOSE_SIMPLE = 0
const VERBOSE_TRACE = 3

Private Attributes

 $raw

Detailed Description

Class Config

This class handles the configuration settings for the Bearsampp application. It reads the configuration from an INI file and provides methods to access and modify these settings.

Definition at line 17 of file class.config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Constructs a Config object and initializes the configuration settings. Reads the configuration from the INI file and sets the default timezone.

Definition at line 49 of file class.config.php.

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 }
global $bearsamppRoot

References $bearsamppRoot, and getTimezone().

Member Function Documentation

◆ getBrowser()

getBrowser ( )

Retrieves the browser setting from the configuration.

Returns
string The browser setting.

Definition at line 165 of file class.config.php.

166 {
167 return $this->raw[self::CFG_BROWSER];
168 }

◆ getDefaultLang()

getDefaultLang ( )

Retrieves the default language setting from the configuration.

Returns
string The default language setting.

Definition at line 115 of file class.config.php.

116 {
117 return $this->raw[self::CFG_DEFAULT_LANG];
118 }

◆ getDownloadId()

getDownloadId ( )

Retrieves the license key from the configuration.

Returns
string The license key.

Definition at line 135 of file class.config.php.

136 {
137 return $this->raw[self::DOWNLOAD_ID];
138 }

◆ getEnhancedQuickPick()

getEnhancedQuickPick ( )

Retrieves the EnhancedQuickPick setting from the configuration.

Returns
int 1 if enhanced mode is enabled, 0 otherwise

Definition at line 235 of file class.config.php.

236 {
237 return isset($this->raw[self::CFG_ENHANCED_QUICKPICK]) ? intval($this->raw[self::CFG_ENHANCED_QUICKPICK]) : 0;
238 }

◆ getHostname()

getHostname ( )

Retrieves the hostname setting from the configuration.

Returns
string The hostname setting.

Definition at line 175 of file class.config.php.

176 {
177 return $this->raw[self::CFG_HOSTNAME];
178 }

◆ getIncludePr()

getIncludePr ( )

Retrieves the IncludePr setting from the configuration.

Returns
int 1 if PR should be included, 0 otherwise

Definition at line 225 of file class.config.php.

226 {
227 return isset($this->raw[self::CFG_INCLUDE_PR]) ? intval($this->raw[self::CFG_INCLUDE_PR]) : 0;
228 }

◆ getLang()

getLang ( )

Retrieves the language setting from the configuration.

Returns
string The language setting.

Definition at line 105 of file class.config.php.

106 {
107 return $this->raw[self::CFG_LANG];
108 }

◆ getLogsVerbose()

getLogsVerbose ( )

Retrieves the logs verbosity setting from the configuration.

Returns
int The logs verbosity setting.

Definition at line 205 of file class.config.php.

206 {
207 return intval($this->raw[self::CFG_LOGS_VERBOSE]);
208 }

◆ getMaxLogsArchives()

getMaxLogsArchives ( )

Retrieves the maximum logs archives setting from the configuration.

Returns
int The maximum logs archives setting.

Definition at line 215 of file class.config.php.

216 {
217 return intval($this->raw[self::CFG_MAX_LOGS_ARCHIVES]);
218 }

◆ getNotepad()

getNotepad ( )

Retrieves the notepad setting from the configuration.

Returns
string The notepad setting.

Definition at line 195 of file class.config.php.

196 {
197 return $this->raw[self::CFG_NOTEPAD];
198 }

◆ getRaw()

getRaw ( $key)

Retrieves the raw configuration value for the specified key.

Parameters
string$keyThe configuration key.
Returns
mixed The configuration value.

Definition at line 64 of file class.config.php.

65 {
66 return $this->raw[$key];
67 }

◆ getScriptsTimeout()

getScriptsTimeout ( )

Retrieves the scripts timeout setting from the configuration.

Returns
int The scripts timeout setting.

Definition at line 185 of file class.config.php.

186 {
187 return intval($this->raw[self::CFG_SCRIPTS_TIMEOUT]);
188 }

◆ getTimezone()

getTimezone ( )

Retrieves the timezone setting from the configuration.

Returns
string The timezone setting.

Definition at line 125 of file class.config.php.

126 {
127 return $this->raw[self::CFG_TIMEZONE];
128 }

Referenced by __construct().

◆ isLaunchStartup()

isLaunchStartup ( )

Checks if the application is set to launch at startup.

Returns
bool True if set to launch at startup, false otherwise.

Definition at line 155 of file class.config.php.

156 {
157 return $this->raw[self::CFG_LAUNCH_STARTUP] == self::ENABLED;
158 }

◆ isOnline()

isOnline ( )

Checks if the application is set to be online.

Returns
bool True if online, false otherwise.

Definition at line 145 of file class.config.php.

146 {
147 return $this->raw[self::CFG_ONLINE] == self::ENABLED;
148 }

◆ replace()

replace ( $key,
$value )

Replaces a single configuration value with the specified key and value.

Parameters
string$keyThe configuration key.
mixed$valueThe new configuration value.

Definition at line 75 of file class.config.php.

76 {
77 $this->replaceAll(array($key => $value));
78 }
replaceAll($params)

References replaceAll().

◆ replaceAll()

replaceAll ( $params)

Replaces multiple configuration values with the specified key-value pairs.

Parameters
array$paramsAn associative array of key-value pairs to replace.

Definition at line 85 of file class.config.php.

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 }
static logTrace($data, $file=null)

References $bearsamppRoot, and Util\logTrace().

Referenced by replace().

◆ validateEnhancedQuickPick()

validateEnhancedQuickPick ( )

Validates that the EnhancedQuickPick parameter exists and has a valid value.

Returns
array An array with 'valid' boolean and optional 'error' message

Definition at line 245 of file class.config.php.

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 }

Field Documentation

◆ $raw

$raw
private

Definition at line 43 of file class.config.php.

◆ CFG_BROWSER

const CFG_BROWSER = 'browser'

◆ CFG_DEFAULT_LANG

const CFG_DEFAULT_LANG = 'defaultLang'

Definition at line 29 of file class.config.php.

◆ CFG_ENHANCED_QUICKPICK

const CFG_ENHANCED_QUICKPICK = 'EnhancedQuickPick'

Definition at line 28 of file class.config.php.

◆ CFG_HOSTNAME

const CFG_HOSTNAME = 'hostname'

Definition at line 30 of file class.config.php.

Referenced by ActionReload\__construct(), and ActionStartup\refreshHostname().

◆ CFG_INCLUDE_PR

const CFG_INCLUDE_PR = 'IncludePR'

Definition at line 27 of file class.config.php.

◆ CFG_LANG

const CFG_LANG = 'lang'

Definition at line 21 of file class.config.php.

Referenced by ActionSwitchLang\__construct().

◆ CFG_LAUNCH_STARTUP

const CFG_LAUNCH_STARTUP = 'launchStartup'

Definition at line 33 of file class.config.php.

Referenced by ActionLaunchStartup\__construct(), and ActionReload\__construct().

◆ CFG_LOGS_VERBOSE

const CFG_LOGS_VERBOSE = 'logsVerbose'

Definition at line 20 of file class.config.php.

Referenced by ActionSwitchLogsVerbose\__construct().

◆ CFG_MAX_LOGS_ARCHIVES

const CFG_MAX_LOGS_ARCHIVES = 'maxLogsArchives'

Definition at line 19 of file class.config.php.

◆ CFG_NOTEPAD

const CFG_NOTEPAD = 'notepad'

Definition at line 23 of file class.config.php.

◆ CFG_ONLINE

const CFG_ONLINE = 'online'

Definition at line 32 of file class.config.php.

Referenced by ActionSwitchOnline\__construct().

◆ CFG_SCRIPTS_TIMEOUT

const CFG_SCRIPTS_TIMEOUT = 'scriptsTimeout'

Definition at line 24 of file class.config.php.

◆ CFG_TIMEZONE

const CFG_TIMEZONE = 'timezone'

Definition at line 22 of file class.config.php.

◆ DISABLED

◆ DOWNLOAD_ID

const DOWNLOAD_ID = 'DownloadId'

Definition at line 25 of file class.config.php.

◆ ENABLED

◆ VERBOSE_DEBUG

const VERBOSE_DEBUG = 2

Definition at line 40 of file class.config.php.

Referenced by TplAppLogsVerbose\getMenuLogsVerbose(), and Util\log().

◆ VERBOSE_REPORT

const VERBOSE_REPORT = 1

Definition at line 39 of file class.config.php.

Referenced by TplAppLogsVerbose\getMenuLogsVerbose(), and Util\log().

◆ VERBOSE_SIMPLE

const VERBOSE_SIMPLE = 0

Definition at line 38 of file class.config.php.

Referenced by TplAppLogsVerbose\getMenuLogsVerbose(), and Util\log().

◆ VERBOSE_TRACE

const VERBOSE_TRACE = 3

Definition at line 41 of file class.config.php.

Referenced by TplAppLogsVerbose\getMenuLogsVerbose(), and Util\log().


The documentation for this class was generated from the following file: