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

Public Member Functions

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

Data Fields

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
 $currentPath
 $enable
 $name
 $release = 'N/A'
 $rootPath
 $symlinkPath
 $version

Private Member Functions

 createSymlink ()

Private Attributes

 $id
 $type

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

36 {
37 // Initialization logic can be added here if needed
38 }

Member Function Documentation

◆ __toString()

__toString ( )

Returns the name of the module.

Returns
string The name of the module.

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

165 {
166 return $this->getName();
167 }

References getName().

◆ createSymlink()

createSymlink ( )
private

Creates a symbolic link from the current path to the symlink path. If the symlink already exists and points to the correct target, no action is taken.

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

82 {
83 $src = UtilPath::formatWindowsPath($this->currentPath);
84 $dest = UtilPath::formatWindowsPath($this->symlinkPath);
85
86 if(file_exists($dest)) {
87 if (is_link($dest)) {
88 $target = readlink($dest);
89 if ($target == $src) {
90 return;
91 }
93 } elseif (is_file($dest)) {
94 Log::error('Removing . ' . $this->symlinkPath . ' file. It should not be a regular file');
95 unlink($dest);
96 } elseif (is_dir($dest)) {
97 // Never recursively delete here: this path is expected to be a symlink.
98 // Only remove empty directories; otherwise abort to avoid data loss.
99 $it = new \FilesystemIterator($dest);
100 if (!$it->valid()) {
101 rmdir($dest);
102 } else {
103 Log::error($this->symlinkPath . ' should be a symlink to ' . $this->currentPath . '. Please remove this dir and restart bearsampp.');
104 return;
105 }
106 }
107 }
108
109 Batch::createSymlink($src, $dest);
110 }
static removeSymlink($link)
static createSymlink($src, $dest)
static error($data, $file=null)
static formatWindowsPath($path)

References Batch\createSymlink(), Log\error(), UtilPath\formatWindowsPath(), and Batch\removeSymlink().

Referenced by reload().

◆ getCurrentPath()

getCurrentPath ( )

Gets the current path of the module.

Returns
string The current path of the module.

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

244 {
245 return $this->currentPath;
246 }

References $currentPath.

Referenced by BinPhp\getApacheModule(), BinPhp\getExtensionsFromFolder(), BinPhp\getPearVersion(), BinPhp\getTsDll(), BinMariadb\initData(), BinMysql\initData(), BinPostgresql\initData(), BinMysql\updateConfig(), and BinPostgresql\updateConfig().

◆ getId()

getId ( )

Gets the ID of the module.

Returns
string The ID of the module.

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

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

References $id.

◆ getName()

◆ getRelease()

getRelease ( )

Gets the release information of the module.

Returns
string The release information.

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

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

References $release.

◆ getRootPath()

getRootPath ( )

Gets the root path of the module.

Returns
string The root path of the module.

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

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

References $rootPath.

◆ getSymlinkPath()

getSymlinkPath ( )

Gets the symlink path of the module.

Returns
string The symlink path of the module.

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

253 {
254 return $this->symlinkPath;
255 }

References $symlinkPath.

Referenced by AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), and ToolGit\updateConfig().

◆ getType()

getType ( )

Gets the type of the module.

Returns
string The type of the module.

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

174 {
175 return $this->type;
176 }

References $type.

◆ getVersion()

◆ getVersionList()

getVersionList ( )

Gets the list of available versions for the module.

Returns
array The list of available versions.

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

210 {
211 return Util::getVersionList($this->rootPath);
212 }
static getVersionList($path)

References Util\getVersionList().

Referenced by BinPhp\getApacheModule().

◆ isEnable()

isEnable ( )

Checks if the module is enabled.

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

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

262 {
263 return $this->enable;
264 }

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

46 {
47 global $bearsamppRoot;
48
49 $this->id = empty($id) ? $this->id : $id;
50 $this->type = empty($type) ? $this->type : $type;
51 $mainPath = 'N/A';
52
53 switch ($this->type) {
54 case Apps::TYPE:
55 $mainPath = $bearsamppRoot->getAppsPath();
56 break;
57 case Bins::TYPE:
58 $mainPath = $bearsamppRoot->getBinPath();
59 break;
60 case Tools::TYPE:
61 $mainPath = $bearsamppRoot->getToolsPath();
62 break;
63 }
64
65 $this->rootPath = $mainPath . '/' . $this->id;
66 $this->currentPath = $this->rootPath . '/' . $this->id . $this->version;
67 $this->symlinkPath = $this->rootPath . '/current';
68 $this->enable = is_dir($this->currentPath);
69 $this->bearsamppConf = $this->currentPath . '/bearsampp.conf';
70 $this->bearsamppConfRaw = @parse_ini_file($this->bearsamppConf);
71
72 if ($bearsamppRoot->isRoot()) {
73 $this->createSymlink();
74 }
75 }
global $bearsamppRoot
const TYPE
const TYPE
createSymlink()
const TYPE

References $bearsamppRoot, $id, $type, $version, createSymlink(), Apps\TYPE, Bins\TYPE, and Tools\TYPE.

◆ replace()

replace ( $key,
$value )
protected

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

127 {
128 $content = file_get_contents($this->bearsamppConf);
129
130 foreach ($params as $key => $value) {
131 $content = preg_replace('|' . $key . ' = .*|', $key . ' = ' . '"' . $value.'"', $content);
132 $this->bearsamppConfRaw[$key] = $value;
133 }
134
135 file_put_contents($this->bearsamppConf, $content);
136 }

Referenced by replace().

◆ setVersion()

setVersion ( $version)
abstract

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

144 {
145 $this->updateConfig(null, $sub, $showWindow);
146 }
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().

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

155 {
156 $version = $version == null ? $this->version : $version;
157 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
158 }
static debug($data, $file=null)

References $version, and Log\debug().

Referenced by update().

Field Documentation

◆ $bearsamppConf

◆ $bearsamppConfRaw

◆ $currentPath

◆ $enable

$enable
protected

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

Referenced by isEnable().

◆ $id

◆ $name

◆ $release

$release = 'N/A'
protected

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

Referenced by getRelease().

◆ $rootPath

$rootPath
protected

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

Referenced by getRootPath().

◆ $symlinkPath

$symlinkPath
protected

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

Referenced by getSymlinkPath().

◆ $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: