Bearsampp 2025.8.29
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 162 of file class.module.php.

162 {
163 return $this->getName();
164 }

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 = Util::formatWindowsPath($this->currentPath);
84 $dest = Util::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 Util::logError('Removing . ' . $this->symlinkPath . ' file. It should not be a regular file');
95 unlink($dest);
96 } elseif (is_dir($dest)) {
97 if (!(new \FilesystemIterator($dest))->valid()) {
98 rmdir($dest);
99 } else {
100 Util::logError($this->symlinkPath . ' should be a symlink to ' . $this->currentPath . '. Please remove this dir and restart bearsampp.');
101 return;
102 }
103 }
104 }
105
106 Batch::createSymlink($src, $dest);
107 }
static removeSymlink($link)
static createSymlink($src, $dest)
static logError($data, $file=null)
static formatWindowsPath($path)

References Batch\createSymlink(), Util\formatWindowsPath(), Util\logError(), 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 241 of file class.module.php.

241 {
242 return $this->currentPath;
243 }

References $currentPath.

Referenced by BinPhp\getApacheModule(), BinPhp\getExtensionsFromFolder(), BinPhp\getPearVersion(), BinPhp\getTsDll(), 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 180 of file class.module.php.

180 {
181 return $this->id;
182 }

References $id.

◆ getName()

◆ getRelease()

getRelease ( )

Gets the release information of the module.

Returns
string The release information.

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

223 {
224 return $this->release;
225 }

References $release.

◆ getRootPath()

getRootPath ( )

Gets the root path of the module.

Returns
string The root path of the module.

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

232 {
233 return $this->rootPath;
234 }

References $rootPath.

◆ getSymlinkPath()

getSymlinkPath ( )

Gets the symlink path of the module.

Returns
string The symlink path of the module.

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

250 {
251 return $this->symlinkPath;
252 }

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

171 {
172 return $this->type;
173 }

References $type.

◆ getVersion()

◆ getVersionList()

getVersionList ( )

Gets the list of available versions for the module.

Returns
array The list of available versions.

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

207 {
208 return Util::getVersionList($this->rootPath);
209 }
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 259 of file class.module.php.

259 {
260 return $this->enable;
261 }

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, ToolConsoleZ, ToolGhostscript, ToolGit, ToolNgrok, ToolPerl, 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 124 of file class.module.php.

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

Referenced by replace().

◆ 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, ToolConsoleZ, ToolGhostscript, ToolGit, ToolNgrok, ToolPerl, 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 141 of file class.module.php.

141 {
142 $this->updateConfig(null, $sub, $showWindow);
143 }
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 152 of file class.module.php.

152 {
153 $version = $version == null ? $this->version : $version;
154 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
155 }
static logDebug($data, $file=null)

References $version, and Util\logDebug().

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: