Bearsampp
2026.7.11
Toggle main menu visibility
Loading...
Searching...
No Matches
class.module.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2024 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
14
abstract
class
Module
15
{
16
const
BUNDLE_RELEASE
=
'bundleRelease'
;
17
18
private
static
$configCache
= array();
19
20
private
$type
;
21
private
$id
;
22
23
protected
$name
;
24
protected
$version
;
25
protected
$release
=
'N/A'
;
26
27
public
$rootPath
;
28
public
$currentPath
;
29
public
$symlinkPath
;
30
protected
$enable
;
31
protected
$bearsamppConf
;
32
protected
$bearsamppConfRaw
;
33
38
protected
function
__construct
() {
39
// Initialization logic can be added here if needed
40
}
41
48
protected
function
reload
(
$id
=
null
,
$type
=
null
) {
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
93
if
(!
Symlinks::isSkippingSymlinkCreation
()) {
94
Symlinks::createModuleSymlink
($this);
95
}
96
}
97
98
105
protected
function
replace
($key, $value) {
106
$this->
replaceAll
(array($key => $value));
107
}
108
114
protected
function
replaceAll
($params) {
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
}
127
134
public
static
function
invalidateConfigCacheForPath
($sourcePath) {
135
$cacheKey = md5($sourcePath);
136
unset(self::$configCache[$cacheKey]);
137
CacheManager::invalidate
($sourcePath);
138
}
139
143
public
static
function
clearMemoryCache
() {
144
self::$configCache = array();
145
}
146
153
public
function
update
($sub = 0, $showWindow =
false
) {
154
$this->
updateConfig
(
null
, $sub, $showWindow);
155
}
156
164
protected
function
updateConfig
(
$version
=
null
, $sub = 0, $showWindow =
false
) {
165
$version
=
$version
==
null
? $this->version :
$version
;
166
Log::debug
(($sub > 0 ? str_repeat(
' '
, 2 * $sub) :
''
) .
'Update '
. $this->name .
' '
.
$version
.
' config'
);
167
}
168
174
public
function
__toString
() {
175
return
$this->
getName
();
176
}
177
183
public
function
getType
() {
184
return
$this->type
;
185
}
186
192
public
function
getId
() {
193
return
$this->id
;
194
}
195
201
public
function
getName
() {
202
return
$this->name
;
203
}
204
210
public
function
getVersion
() {
211
return
$this->version
;
212
}
213
219
public
function
getVersionList
() {
220
return
Util::getVersionList
($this->rootPath);
221
}
222
228
abstract
public
function
setVersion
(
$version
);
229
235
public
function
getRelease
() {
236
return
$this->release
;
237
}
238
239
245
public
function
isEnable
() {
246
return
$this->enable
;
247
}
248
249
}
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
Apps\TYPE
const TYPE
Definition
class.apps.php:21
Bins\TYPE
const TYPE
Definition
class.bins.php:18
CacheManager\load
static load(string $sourcePath, callable $parser, ?string $cacheKey=null)
Definition
class.cachemanager.php:61
CacheManager\invalidate
static invalidate(string $sourcePath)
Definition
class.cachemanager.php:159
Log\debug
static debug($data, $file=null)
Definition
class.log.php:616
Module
Definition
class.module.php:15
Module\$bearsamppConf
$bearsamppConf
Definition
class.module.php:31
Module\__construct
__construct()
Definition
class.module.php:38
Module\getId
getId()
Definition
class.module.php:192
Module\$version
$version
Definition
class.module.php:24
Module\$configCache
static $configCache
Definition
class.module.php:18
Module\$bearsamppConfRaw
$bearsamppConfRaw
Definition
class.module.php:32
Module\$rootPath
$rootPath
Definition
class.module.php:27
Module\isEnable
isEnable()
Definition
class.module.php:245
Module\replaceAll
replaceAll($params)
Definition
class.module.php:114
Module\getName
getName()
Definition
class.module.php:201
Module\update
update($sub=0, $showWindow=false)
Definition
class.module.php:153
Module\clearMemoryCache
static clearMemoryCache()
Definition
class.module.php:143
Module\updateConfig
updateConfig($version=null, $sub=0, $showWindow=false)
Definition
class.module.php:164
Module\BUNDLE_RELEASE
const BUNDLE_RELEASE
Definition
class.module.php:16
Module\$release
$release
Definition
class.module.php:25
Module\setVersion
setVersion($version)
Module\invalidateConfigCacheForPath
static invalidateConfigCacheForPath($sourcePath)
Definition
class.module.php:134
Module\$symlinkPath
$symlinkPath
Definition
class.module.php:29
Module\__toString
__toString()
Definition
class.module.php:174
Module\$currentPath
$currentPath
Definition
class.module.php:28
Module\getType
getType()
Definition
class.module.php:183
Module\$type
$type
Definition
class.module.php:20
Module\getRelease
getRelease()
Definition
class.module.php:235
Module\replace
replace($key, $value)
Definition
class.module.php:105
Module\$name
$name
Definition
class.module.php:23
Module\reload
reload($id=null, $type=null)
Definition
class.module.php:48
Module\$enable
$enable
Definition
class.module.php:30
Module\$id
$id
Definition
class.module.php:21
Module\getVersionList
getVersionList()
Definition
class.module.php:219
Module\getVersion
getVersion()
Definition
class.module.php:210
Path\getToolsPath
static getToolsPath($aetrayPath=false)
Definition
class.path.php:951
Path\getBinPath
static getBinPath($aetrayPath=false)
Definition
class.path.php:364
Path\getAppsPath
static getAppsPath($aetrayPath=false)
Definition
class.path.php:342
Symlinks\createModuleSymlink
static createModuleSymlink($module)
Definition
class.symlinks.php:96
Symlinks\isSkippingSymlinkCreation
static isSkippingSymlinkCreation()
Definition
class.symlinks.php:85
Tools\TYPE
const TYPE
Definition
class.tools.php:22
Util\getVersionList
static getVersionList($path)
Definition
class.util.php:337
sandbox
core
classes
class.module.php
Generated by
1.17.0