2024.8.23
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()

Module::__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()

Module::__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()

Module::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().

+ Here is the caller graph for this function:

◆ getCurrentPath()

Module::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().

+ Here is the caller graph for this function:

◆ getId()

Module::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()

Module::getName ( )

Gets the name of the module.

Returns
string The name of the module.

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

189 {
190 return $this->name;
191 }

References $name.

Referenced by __toString(), BinApache\changePort(), BinFilezilla\changePort(), BinMailhog\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinApache\checkPort(), BinFilezilla\checkPort(), BinMailhog\checkPort(), BinMailpit\checkPort(), BinMariadb\checkPort(), BinMemcached\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), BinXlight\checkPort(), BinApache\reload(), BinFilezilla\reload(), BinMailhog\reload(), BinMailpit\reload(), BinMariadb\reload(), BinMemcached\reload(), BinMysql\reload(), BinPostgresql\reload(), BinXlight\reload(), BinApache\setEnable(), BinFilezilla\setEnable(), BinMailhog\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinNodejs\setEnable(), BinPhp\setEnable(), BinPostgresql\setEnable(), BinXlight\setEnable(), AppAdminer\updateConfig(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), AppWebgrind\updateConfig(), BinApache\updateConfig(), BinFilezilla\updateConfig(), BinMailhog\updateConfig(), BinMailpit\updateConfig(), BinMariadb\updateConfig(), BinMemcached\updateConfig(), BinMysql\updateConfig(), BinNodejs\updateConfig(), BinPhp\updateConfig(), BinPostgresql\updateConfig(), and BinXlight\updateConfig().

◆ getRelease()

Module::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()

Module::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()

Module::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 AppAdminer\updateConfig(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), AppWebgrind\updateConfig(), and ToolGit\updateConfig().

+ Here is the caller graph for this function:

◆ getType()

Module::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()

Module::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().

+ Here is the caller graph for this function:

◆ isEnable()

Module::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()

Module::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 AppAdminer, AppPhpmyadmin, AppPhppgadmin, AppWebgrind, BinApache, BinFilezilla, BinMailhog, BinMailpit, BinMariadb, BinMemcached, BinMysql, BinNodejs, BinPhp, BinPostgresql, BinXlight, ToolComposer, ToolConsoleZ, ToolGhostscript, ToolGit, ToolNgrok, ToolPerl, ToolPython, ToolRuby, ToolXdc, and ToolYarn.

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()

Module::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 115 of file class.module.php.

115 {
116 $this->replaceAll(array($key => $value));
117 }
replaceAll($params)

References replaceAll().

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

+ Here is the caller graph for this function:

◆ replaceAll()

Module::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, BinFilezilla, BinMailhog, 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().

+ Here is the caller graph for this function:

◆ setVersion()

Module::setVersion ( $version)
abstract

◆ update()

Module::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(), BinFilezilla\changePort(), BinMailhog\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinMariadb\changeRootPassword(), BinMysql\changeRootPassword(), and BinPostgresql\changeRootPassword().

+ Here is the caller graph for this function:

◆ updateConfig()

Module::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 AppAdminer, AppPhpmyadmin, AppPhppgadmin, AppWebgrind, BinApache, BinFilezilla, BinMailhog, 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().

+ Here is the caller graph for this function:

Field Documentation

◆ $bearsamppConf

◆ $bearsamppConfRaw

◆ $currentPath

Module::$currentPath
protected

◆ $enable

Module::$enable
protected

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

Referenced by isEnable().

◆ $id

◆ $name

◆ $release

Module::$release = 'N/A'
protected

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

Referenced by getRelease().

◆ $rootPath

Module::$rootPath
protected

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

Referenced by getRootPath().

◆ $symlinkPath

Module::$symlinkPath
protected

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

Referenced by getSymlinkPath().

◆ $type

◆ $version

Module::$version
protected

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

Referenced by BinMariadb\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), BinApache\getOfflineContent(), BinApache\getOnlineContent(), BinApache\getRequiredContent(), getVersion(), BinMysql\initData(), reload(), AppWebgrind\setVersion(), BinApache\setVersion(), BinFilezilla\setVersion(), BinMailhog\setVersion(), BinMailpit\setVersion(), BinMariadb\setVersion(), BinMemcached\setVersion(), BinMysql\setVersion(), BinNodejs\setVersion(), BinPhp\setVersion(), BinPostgresql\setVersion(), BinXlight\setVersion(), ToolComposer\setVersion(), ToolConsoleZ\setVersion(), ToolGhostscript\setVersion(), ToolGit\setVersion(), ToolNgrok\setVersion(), ToolPerl\setVersion(), ToolPython\setVersion(), ToolRuby\setVersion(), ToolXdc\setVersion(), ToolYarn\setVersion(), BinApache\switchVersion(), BinFilezilla\switchVersion(), BinMailhog\switchVersion(), BinMailpit\switchVersion(), BinMariadb\switchVersion(), BinMemcached\switchVersion(), BinMysql\switchVersion(), BinNodejs\switchVersion(), BinPhp\switchVersion(), BinPostgresql\switchVersion(), BinXlight\switchVersion(), AppAdminer\updateConfig(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), AppWebgrind\updateConfig(), BinApache\updateConfig(), BinFilezilla\updateConfig(), BinMailhog\updateConfig(), BinMailpit\updateConfig(), BinMariadb\updateConfig(), BinMemcached\updateConfig(), BinMysql\updateConfig(), BinNodejs\updateConfig(), BinPhp\updateConfig(), BinPostgresql\updateConfig(), BinXlight\updateConfig(), updateConfig(), and ToolGit\updateConfig().

◆ BUNDLE_RELEASE

const Module::BUNDLE_RELEASE = 'bundleRelease'

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


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