Bearsampp 2026.9.23
Loading...
Searching...
No Matches
Module Class Reference
Inheritance diagram for Module:

Public Member Functions

 __toString ()
 getId ()
 getName ()
 getRelease ()
 getType ()
 getVersion ()
 getVersionList ()
 isEnable ()
 setVersion ($version)
 update ($sub=0, $showWindow=false)

Static Public Member Functions

static clearMemoryCache ()
static invalidateConfigCacheForPath ($sourcePath)

Data Fields

 $currentPath
 $rootPath
 $symlinkPath

Protected Member Functions

 __construct ()
 reload ($id=null, $type=null)
 replace ($key, $value)
 replaceAll ($params)
 updateConfig ($version=null, $sub=0, $showWindow=false)

Protected Attributes

 $bearsamppConf
 $bearsamppConfRaw
 $enable
 $name
 $release = 'N/A'
 $version

Private Attributes

 $id
 $type

Static Private Attributes

static $configCache = array()

Detailed Description

Abstract class representing a module in the Bearsampp application. This class provides common functionalities for managing modules such as apps, bins, and tools.

Definition at line 14 of file class.module.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )
protected

Constructor for the Module class. Initializes the module with default values.

Definition at line 56 of file class.module.php.

57 {
58 // Initialization logic can be added here if needed
59 }

Member Function Documentation

◆ __toString()

__toString ( )

Returns the name of the module.

Returns
string The name of the module.

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

216 {
217 return $this->getName();
218 }

References getName().

Here is the call graph for this function:

◆ clearMemoryCache()

clearMemoryCache ( )
static

Clears all in-memory configuration caches.

Definition at line 181 of file class.module.php.

182 {
183 self::$configCache = array();
184 }

Referenced by CacheManager\clearAll().

Here is the caller graph for this function:

◆ getId()

getId ( )

Gets the ID of the module.

Returns
string The ID of the module.

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

236 {
237 return $this->id;
238 }

References $id.

◆ getName()

◆ getRelease()

getRelease ( )

Gets the release information of the module.

Returns
string The release information.

Definition at line 282 of file class.module.php.

283 {
284 return $this->release;
285 }

References $release.

◆ getType()

getType ( )

Gets the type of the module.

Returns
string The type of the module.

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

226 {
227 return $this->type;
228 }

References $type.

◆ getVersion()

◆ getVersionList()

getVersionList ( )

Gets the list of available versions for the module.

Returns
array The list of available versions.

Definition at line 265 of file class.module.php.

266 {
267 return Util::getVersionList($this->rootPath);
268 }
static getVersionList($path)

References Util\getVersionList().

Referenced by BinPhp\getApacheModule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invalidateConfigCacheForPath()

invalidateConfigCacheForPath ( $sourcePath)
static

Invalidates the configuration cache for a given source path. Clears both in-memory cache and disk cache via CacheManager.

Parameters
string$sourcePathThe path to the configuration file to invalidate cache for.

Definition at line 171 of file class.module.php.

172 {
173 $cacheKey = md5($sourcePath);
174 unset(self::$configCache[$cacheKey]);
175 CacheManager::invalidate($sourcePath);
176 }
static invalidate(string $sourcePath)

References CacheManager\invalidate().

Referenced by BinApache\replaceAll(), BinMailpit\replaceAll(), BinMariadb\replaceAll(), BinMemcached\replaceAll(), BinMysql\replaceAll(), BinPostgresql\replaceAll(), BinXlight\replaceAll(), replaceAll(), and BinMysql\updateConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEnable()

isEnable ( )

Checks if the module is enabled.

Returns
bool True if the module is enabled, false otherwise.

Definition at line 293 of file class.module.php.

294 {
295 return $this->enable;
296 }

References $enable.

◆ reload()

reload ( $id = null,
$type = null )
protected

Reloads the module configuration based on the provided ID and type.

Parameters
string | null$idThe ID of the module. If null, the current ID is used.
string | null$typeThe type of the module. If null, the current type is used.

Reimplemented in AppPhpmyadmin, AppPhppgadmin, BinApache, BinMailpit, BinMariadb, BinMemcached, BinMysql, BinNodejs, BinPhp, BinPostgresql, BinXlight, ToolBruno, ToolComposer, ToolGhostscript, ToolGit, ToolNgrok, ToolPerl, ToolPowerShell, ToolPython, and ToolRuby.

Definition at line 67 of file class.module.php.

68 {
69 global $bearsamppRoot;
70
71 $this->id = empty($id) ? $this->id : $id;
72 $this->type = empty($type) ? $this->type : $type;
73 $mainPath = 'N/A';
74
75 switch ($this->type) {
76 case Apps::TYPE:
77 $mainPath = Path::getAppsPath();
78 break;
79 case Bins::TYPE:
80 $mainPath = Path::getBinPath();
81 break;
82 case Tools::TYPE:
83 $mainPath = Path::getToolsPath();
84 break;
85 }
86
87 $this->rootPath = $mainPath . '/' . $this->id;
88 $this->currentPath = $this->rootPath . '/' . $this->id . $this->version;
89 $this->symlinkPath = $this->rootPath . '/current';
90 $this->enable = is_dir($this->currentPath);
91 $this->bearsamppConf = $this->currentPath . '/bearsampp.conf';
92
93 $cacheKey = md5($this->bearsamppConf);
94 if (!isset(self::$configCache[$cacheKey])) {
95 // CacheManager handles both disk cache and parsing
96 $data = CacheManager::load(
97 $this->bearsamppConf,
98 function ($path) {
99 return @parse_ini_file($path) ?: [];
100 },
101 $cacheKey
102 );
103
104 if (!empty($data)) {
105 $this->bearsamppConfRaw = $data;
106 self::$configCache[$cacheKey] = $this->bearsamppConfRaw;
107 } else {
108 $this->bearsamppConfRaw = [];
109 // Do not cache empty results in memory to allow retry on next reload
110 }
111 } else {
112 $this->bearsamppConfRaw = self::$configCache[$cacheKey];
113 }
114
117 }
118 }
global $bearsamppRoot
const TYPE
const TYPE
static load(string $sourcePath, callable $parser, ?string $cacheKey=null)
static getToolsPath($aetrayPath=false)
static getBinPath($aetrayPath=false)
static getAppsPath($aetrayPath=false)
const TYPE

References $bearsamppConfRaw, $bearsamppRoot, $id, $type, $version, Symlinks\createModuleSymlink(), Path\getAppsPath(), Path\getBinPath(), Path\getToolsPath(), Symlinks\isSkippingSymlinkCreation(), CacheManager\load(), Apps\TYPE, Bins\TYPE, and Tools\TYPE.

Here is the call graph for this function:

◆ replace()

replace ( $key,
$value )
protected

Replaces a specific key-value pair in the configuration file.

Parameters
string$keyThe key to replace.
string$valueThe new value for the key.

Definition at line 127 of file class.module.php.

128 {
129 $this->replaceAll(array($key => $value));
130 }
replaceAll($params)

References replaceAll().

Referenced by BinMailpit\setListen(), BinMemcached\setMemory(), BinApache\setPort(), BinMariadb\setPort(), BinMemcached\setPort(), BinMysql\setPort(), BinPostgresql\setPort(), BinXlight\setPort(), BinMariadb\setRootPwd(), BinMysql\setRootPwd(), BinPostgresql\setRootPwd(), BinMariadb\setRootUser(), BinMysql\setRootUser(), BinPostgresql\setRootUser(), BinMailpit\setSmtpPort(), BinApache\setSslPort(), BinXlight\setSslPort(), BinMailpit\setUiPort(), and BinMailpit\setWebRoot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replaceAll()

replaceAll ( $params)
protected

Replaces multiple key-value pairs in the configuration file.

Parameters
array$paramsAn associative array of key-value pairs to replace.
Exceptions
RuntimeExceptionIf the configuration key or value is invalid.

Reimplemented in BinApache, BinMailpit, BinMariadb, BinMemcached, BinMysql, BinPostgresql, and BinXlight.

Definition at line 139 of file class.module.php.

140 {
141 $content = file_get_contents($this->bearsamppConf);
142
143 foreach ($params as $key => $value) {
144 // Same hardening as Config::replaceAll() - the key is used in a
145 // regex pattern and the value in the INI content, so both must be
146 // validated to prevent config poisoning.
147 if (!is_string($key) || preg_match('/^[a-zA-Z0-9_-]+$/', $key) !== 1) {
148 throw new RuntimeException('Invalid configuration key: ' . var_export($key, true));
149 }
150 $value = (string)$value;
151 if (preg_match('/[\r\n"\x00-\x1F\x7F]/', $value) === 1) {
152 throw new RuntimeException('Invalid configuration value for key: ' . $key);
153 }
154
155 $content = preg_replace('|' . preg_quote($key, '|') . ' = .*|', $key . ' = ' . '"' . $value . '"', $content);
156 $this->bearsamppConfRaw[$key] = $value;
157 }
158
159 file_put_contents($this->bearsamppConf, $content);
160
161 // Invalidate both memory cache and disk cache
162 self::invalidateConfigCacheForPath($this->bearsamppConf);
163 }
static invalidateConfigCacheForPath($sourcePath)

References invalidateConfigCacheForPath().

Referenced by replace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setVersion()

setVersion ( $version)
abstract

Sets the version of the module.

Parameters
string$versionThe version to set.

Reimplemented in AppPhpmyadmin, AppPhppgadmin, BinApache, BinMailpit, BinMariadb, BinMemcached, BinMysql, BinNodejs, BinPhp, BinPostgresql, BinXlight, ToolBruno, ToolComposer, ToolGhostscript, ToolGit, ToolNgrok, ToolPerl, ToolPowerShell, ToolPython, and ToolRuby.

References $version.

◆ update()

update ( $sub = 0,
$showWindow = false )

Updates the module configuration.

Parameters
int$subThe sub-level for logging indentation.
bool$showWindowWhether to show a window during the update process.

Definition at line 192 of file class.module.php.

193 {
194 $this->updateConfig(null, $sub, $showWindow);
195 }
updateConfig($version=null, $sub=0, $showWindow=false)

References updateConfig().

Referenced by BinApache\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinMariadb\changeRootPassword(), BinMysql\changeRootPassword(), and BinPostgresql\changeRootPassword().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateConfig()

updateConfig ( $version = null,
$sub = 0,
$showWindow = false )
protected

Updates the module configuration with a specific version.

Parameters
string | null$versionThe version to update to. If null, the current version is used.
int$subThe sub-level for logging indentation.
bool$showWindowWhether to show a window during the update process.

Reimplemented in AppPhpmyadmin, AppPhppgadmin, BinApache, BinMailpit, BinMariadb, BinMemcached, BinMysql, BinNodejs, BinPhp, BinPostgresql, BinXlight, and ToolGit.

Definition at line 204 of file class.module.php.

205 {
206 $version = $version == null ? $this->version : $version;
207 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
208 }
static debug($data, $file=null)

References $version, and Log\debug().

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $bearsamppConf

◆ $bearsamppConfRaw

◆ $configCache

$configCache = array()
staticprivate

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

◆ $currentPath

◆ $enable

$enable
protected

Definition at line 44 of file class.module.php.

Referenced by isEnable().

◆ $id

◆ $name

◆ $release

$release = 'N/A'
protected

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

Referenced by getRelease().

◆ $rootPath

$rootPath

Definition at line 35 of file class.module.php.

◆ $symlinkPath

$symlinkPath

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

◆ $type

◆ $version


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