Bearsampp 2026.7.11
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
const BUNDLE_RELEASE = 'bundleRelease'

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 38 of file class.module.php.

38 {
39 // Initialization logic can be added here if needed
40 }

Member Function Documentation

◆ __toString()

__toString ( )

Returns the name of the module.

Returns
string The name of the module.

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

174 {
175 return $this->getName();
176 }

References getName().

Here is the call graph for this function:

◆ clearMemoryCache()

clearMemoryCache ( )
static

Clears all in-memory configuration caches.

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

143 {
144 self::$configCache = array();
145 }

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 192 of file class.module.php.

192 {
193 return $this->id;
194 }

References $id.

◆ getName()

◆ getRelease()

getRelease ( )

Gets the release information of the module.

Returns
string The release information.

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

235 {
236 return $this->release;
237 }

References $release.

◆ getType()

getType ( )

Gets the type of the module.

Returns
string The type of the module.

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

183 {
184 return $this->type;
185 }

References $type.

◆ getVersion()

◆ getVersionList()

getVersionList ( )

Gets the list of available versions for the module.

Returns
array The list of available versions.

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

219 {
220 return Util::getVersionList($this->rootPath);
221 }
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 134 of file class.module.php.

134 {
135 $cacheKey = md5($sourcePath);
136 unset(self::$configCache[$cacheKey]);
137 CacheManager::invalidate($sourcePath);
138 }
static invalidate(string $sourcePath)

References CacheManager\invalidate().

Referenced by 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 245 of file class.module.php.

245 {
246 return $this->enable;
247 }

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 48 of file class.module.php.

48 {
49 global $bearsamppRoot;
50
51 $this->id = empty($id) ? $this->id : $id;
52 $this->type = empty($type) ? $this->type : $type;
53 $mainPath = 'N/A';
54
55 switch ($this->type) {
56 case Apps::TYPE:
57 $mainPath = Path::getAppsPath();
58 break;
59 case Bins::TYPE:
60 $mainPath = Path::getBinPath();
61 break;
62 case Tools::TYPE:
63 $mainPath = Path::getToolsPath();
64 break;
65 }
66
67 $this->rootPath = $mainPath . '/' . $this->id;
68 $this->currentPath = $this->rootPath . '/' . $this->id . $this->version;
69 $this->symlinkPath = $this->rootPath . '/current';
70 $this->enable = is_dir($this->currentPath);
71 $this->bearsamppConf = $this->currentPath . '/bearsampp.conf';
72
73 $cacheKey = md5($this->bearsamppConf);
74 if (!isset(self::$configCache[$cacheKey])) {
75 // CacheManager handles both disk cache and parsing
76 $data = CacheManager::load(
77 $this->bearsamppConf,
78 function($path) { return @parse_ini_file($path) ?: []; },
79 $cacheKey
80 );
81
82 if (!empty($data)) {
83 $this->bearsamppConfRaw = $data;
84 self::$configCache[$cacheKey] = $this->bearsamppConfRaw;
85 } else {
86 $this->bearsamppConfRaw = [];
87 // Do not cache empty results in memory to allow retry on next reload
88 }
89 } else {
90 $this->bearsamppConfRaw = self::$configCache[$cacheKey];
91 }
92
95 }
96 }
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 105 of file class.module.php.

105 {
106 $this->replaceAll(array($key => $value));
107 }
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.

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

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

114 {
115 $content = file_get_contents($this->bearsamppConf);
116
117 foreach ($params as $key => $value) {
118 $content = preg_replace('|' . $key . ' = .*|', $key . ' = ' . '"' . $value.'"', $content);
119 $this->bearsamppConfRaw[$key] = $value;
120 }
121
122 file_put_contents($this->bearsamppConf, $content);
123
124 // Invalidate both memory cache and disk cache
125 self::invalidateConfigCacheForPath($this->bearsamppConf);
126 }
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 153 of file class.module.php.

153 {
154 $this->updateConfig(null, $sub, $showWindow);
155 }
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 164 of file class.module.php.

164 {
165 $version = $version == null ? $this->version : $version;
166 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
167 }
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 18 of file class.module.php.

◆ $currentPath

◆ $enable

$enable
protected

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

Referenced by isEnable().

◆ $id

◆ $name

◆ $release

$release = 'N/A'
protected

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

Referenced by getRelease().

◆ $rootPath

$rootPath

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

◆ $symlinkPath

$symlinkPath

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

◆ $type

◆ $version

◆ BUNDLE_RELEASE

const BUNDLE_RELEASE = 'bundleRelease'

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


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