Bearsampp 2026.9.23
Loading...
Searching...
No Matches
BinNodejs Class Reference
Inheritance diagram for BinNodejs:
Collaboration diagram for BinNodejs:

Public Member Functions

 __construct ($id, $type)
 getConf ()
 getExe ()
 getLaunch ()
 getNpm ()
 getVars ()
 reload ($id=null, $type=null)
 setEnable ($enabled, $showWindow=false)
 setVersion ($version)
 switchVersion ($version, $showWindow=false)
Public Member Functions inherited from Module
 __toString ()
 getId ()
 getName ()
 getRelease ()
 getType ()
 getVersion ()
 getVersionList ()
 isEnable ()
 update ($sub=0, $showWindow=false)

Data Fields

const LOCAL_CFG_CONF = 'nodejsConf'
const LOCAL_CFG_EXE = 'nodejsExe'
const LOCAL_CFG_LAUNCH = 'nodejsLaunch'
const LOCAL_CFG_NPM = 'nodejsNpm'
const LOCAL_CFG_VARS = 'nodejsVars'
const ROOT_CFG_ENABLE = 'nodejsEnable'
const ROOT_CFG_VERSION = 'nodejsVersion'
Data Fields inherited from Module
 $currentPath
 $rootPath
 $symlinkPath

Protected Member Functions

 updateConfig ($version=null, $sub=0, $showWindow=false)
Protected Member Functions inherited from Module
 __construct ()
 replace ($key, $value)
 replaceAll ($params)

Private Attributes

 $conf
 $exe
 $launch
 $npm
 $vars

Additional Inherited Members

Static Public Member Functions inherited from Module
static clearMemoryCache ()
static invalidateConfigCacheForPath ($sourcePath)
Protected Attributes inherited from Module
 $bearsamppConf
 $bearsamppConfRaw
 $enable
 $name
 $release = 'N/A'
 $version

Detailed Description

Class BinNodejs

The BinNodejs class extends the Module class and provides functionalities specific to managing the Node.js module within the Bearsampp application. It includes methods for reloading the module configuration, switching versions, enabling/disabling the module, and retrieving various configuration paths such as the executable, configuration file, variables file, npm executable, and launch script.

Constants:

Properties:

  • exe: Path to the Node.js executable.
  • conf: Path to the Node.js configuration file.
  • vars: Path to the Node.js variables file.
  • npm: Path to the npm executable.
  • launch: Path to the Node.js launch script.

Methods:

  • __construct($id, $type): Constructs a BinNodejs object and initializes the module with the given ID and type.
  • reload($id = null, $type = null): Reloads the module configuration based on the provided ID and type.
  • switchVersion($version, $showWindow = false): Switches the Node.js version to the specified version.
  • updateConfig($version = null, $sub = 0, $showWindow = false): Updates the module configuration with a specific version.
  • setVersion($version): Sets the version of the module.
  • setEnable($enabled, $showWindow = false): Enables or disables the module.
  • getExe(): Retrieves the executable path for Node.js.
  • getConf(): Retrieves the configuration file path for Node.js.
  • getVars(): Retrieves the variables file path for Node.js.
  • getNpm(): Retrieves the npm executable path for Node.js.
  • getLaunch(): Retrieves the launch script path for Node.js.

Definition at line 48 of file class.bin.nodejs.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $id,
$type )

Constructs a BinNodejs object and initializes the module with the given ID and type.

Parameters
string$idThe ID of the module.
string$typeThe type of the module.

Definition at line 107 of file class.bin.nodejs.php.

108 {
109 Log::initClass($this);
110 $this->reload($id, $type);
111 }
reload($id=null, $type=null)
static initClass($classInstance)

References Module\$id, Module\$type, Log\initClass(), and reload().

Here is the call graph for this function:

Member Function Documentation

◆ getConf()

getConf ( )

Retrieves the configuration file path for Node.js.

Returns
string The configuration file path.

Definition at line 300 of file class.bin.nodejs.php.

301 {
302 return $this->conf;
303 }

References $conf.

Referenced by updateConfig().

Here is the caller graph for this function:

◆ getExe()

getExe ( )

Retrieves the executable path for Node.js.

Returns
string The executable path.

Definition at line 290 of file class.bin.nodejs.php.

291 {
292 return $this->exe;
293 }

References $exe.

◆ getLaunch()

getLaunch ( )

Retrieves the launch script path for Node.js.

Returns
string The launch script path.

Definition at line 330 of file class.bin.nodejs.php.

331 {
332 return $this->launch;
333 }

References $launch.

◆ getNpm()

getNpm ( )

Retrieves the npm executable path for Node.js.

Returns
string The npm executable path.

Definition at line 320 of file class.bin.nodejs.php.

321 {
322 return $this->npm;
323 }

References $npm.

◆ getVars()

getVars ( )

Retrieves the variables file path for Node.js.

Returns
string The variables file path.

Definition at line 310 of file class.bin.nodejs.php.

311 {
312 return $this->vars;
313 }

References $vars.

◆ reload()

reload ( $id = null,
$type = null )

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 from Module.

Definition at line 119 of file class.bin.nodejs.php.

120 {
122 Log::reloadClass($this);
123
124 $this->name = $bearsamppLang->getValue(Lang::NODEJS);
125 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
126 parent::reload($id, $type);
127
128 $this->enable = $this->enable && $bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
129
130 if ($this->bearsamppConfRaw !== false) {
131 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
132 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
133 $this->vars = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_VARS];
134 $this->npm = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_NPM];
135 $this->launch = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_LAUNCH];
136 }
137
138 if (!$this->enable) {
139 Log::info($this->name . ' is not enabled!');
140
141 return;
142 }
143 if (!is_dir($this->currentPath)) {
144 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
145
146 return;
147 }
148 if (!is_dir($this->symlinkPath)) {
149 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
150
151 return;
152 }
153 if (!is_file($this->bearsamppConf)) {
154 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
155
156 return;
157 }
158 if (!is_file($this->exe)) {
159 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
160 }
161 if (!is_file($this->conf)) {
162 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
163 }
164 if (!is_file($this->vars)) {
165 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->vars));
166 }
167 if (!is_file($this->npm)) {
168 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->npm));
169 }
170 if (!is_file($this->launch)) {
171 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->launch));
172 }
173 }
global $bearsamppLang
const NODEJS
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const ERROR_FILE_NOT_FOUND
static info($data, $file=null)
static reloadClass($classInstance)
static error($data, $file=null)
global $bearsamppConfig
Definition homepage.php:46

References $bearsamppConfig, $bearsamppLang, Module\$id, Module\$type, Log\error(), Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, Log\info(), Lang\NODEJS, and Log\reloadClass().

Referenced by __construct(), and setVersion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEnable()

setEnable ( $enabled,
$showWindow = false )

Enables or disables the module.

Parameters
int$enabledThe enable status (1 for enabled, 0 for disabled).
bool$showWindowWhether to show a window during the enable/disable process.

Definition at line 265 of file class.bin.nodejs.php.

266 {
267 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
268
269 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
270 Log::debug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
271 if ($showWindow) {
272 $bearsamppWinbinder->messageBoxError(
273 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
274 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
275 );
276 }
277 $enabled = Config::DISABLED;
278 }
279
280 Log::info($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
281 $this->enable = $enabled == Config::ENABLED;
282 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
283 }
const DISABLED
const ENABLED
const ENABLE_BUNDLE_NOT_EXIST
const ENABLE_TITLE
static debug($data, $file=null)

References $bearsamppConfig, $bearsamppLang, Log\debug(), Config\DISABLED, Lang\ENABLE_BUNDLE_NOT_EXIST, Lang\ENABLE_TITLE, Config\ENABLED, Module\getName(), Module\getVersion(), and Log\info().

Here is the call graph for this function:

◆ setVersion()

setVersion ( $version)

Sets the version of the module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

Definition at line 251 of file class.bin.nodejs.php.

252 {
253 global $bearsamppConfig;
254 $this->version = $version;
255 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
256 $this->reload();
257 }

References $bearsamppConfig, Module\$version, and reload().

Referenced by updateConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switchVersion()

switchVersion ( $version,
$showWindow = false )

Switches the Node.js version to the specified version.

Parameters
string$versionThe version to switch to.
bool$showWindowWhether to show a window during the switch process.
Returns
bool True if the switch was successful, false otherwise.

Definition at line 183 of file class.bin.nodejs.php.

184 {
185 Log::debug('Switch ' . $this->name . ' version to ' . $version);
186
187 return $this->updateConfig($version, 0, $showWindow);
188 }
updateConfig($version=null, $sub=0, $showWindow=false)

References Module\$version, Log\debug(), and updateConfig().

Here is the call 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.
Returns
bool True if the update was successful, false otherwise.

Reimplemented from Module.

Definition at line 199 of file class.bin.nodejs.php.

200 {
201 global $bearsamppLang, $bearsamppWinbinder;
202
203 if (!$this->enable) {
204 return true;
205 }
206
207 $version = $version == null ? $this->version : $version;
208 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
209
210 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
211
212 $conf = str_replace('nodejs' . $this->getVersion(), 'nodejs' . $version, $this->getConf());
213 $bearsamppConf = str_replace('nodejs' . $this->getVersion(), 'nodejs' . $version, $this->bearsamppConf);
214
215 if (!file_exists($conf) || !file_exists($bearsamppConf)) {
216 Log::error('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
217 if ($showWindow) {
218 $bearsamppWinbinder->messageBoxError(
219 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
220 $boxTitle
221 );
222 }
223
224 return false;
225 }
226
227 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
228 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
229 Log::error('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
230 if ($showWindow) {
231 $bearsamppWinbinder->messageBoxError(
232 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
233 $boxTitle
234 );
235 }
236
237 return false;
238 }
239
240 // bearsampp.conf
241 $this->setVersion($version);
242
243 return true;
244 }
setVersion($version)
const BEARSAMPP_CONF_MALFORMED_ERROR
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE

References Module\$bearsamppConf, Module\$bearsamppConfRaw, $bearsamppLang, $conf, Module\$version, Lang\BEARSAMPP_CONF_MALFORMED_ERROR, Lang\BEARSAMPP_CONF_NOT_FOUND_ERROR, Log\debug(), Log\error(), getConf(), Module\getName(), Module\getVersion(), setVersion(), and Lang\SWITCH_VERSION_TITLE.

Referenced by switchVersion().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ $conf

$conf
private

Definition at line 87 of file class.bin.nodejs.php.

Referenced by getConf(), and updateConfig().

◆ $exe

$exe
private

Definition at line 83 of file class.bin.nodejs.php.

Referenced by getExe().

◆ $launch

$launch
private

Definition at line 99 of file class.bin.nodejs.php.

Referenced by getLaunch().

◆ $npm

$npm
private

Definition at line 95 of file class.bin.nodejs.php.

Referenced by getNpm().

◆ $vars

$vars
private

Definition at line 91 of file class.bin.nodejs.php.

Referenced by getVars().

◆ LOCAL_CFG_CONF

const LOCAL_CFG_CONF = 'nodejsConf'

Configuration key for the Node.js configuration file.

Definition at line 78 of file class.bin.nodejs.php.

◆ LOCAL_CFG_EXE

const LOCAL_CFG_EXE = 'nodejsExe'

Configuration key for the Node.js executable.

Definition at line 62 of file class.bin.nodejs.php.

◆ LOCAL_CFG_LAUNCH

const LOCAL_CFG_LAUNCH = 'nodejsLaunch'

Configuration key for the Node.js launch script.

Definition at line 74 of file class.bin.nodejs.php.

◆ LOCAL_CFG_NPM

const LOCAL_CFG_NPM = 'nodejsNpm'

Configuration key for the npm executable.

Definition at line 70 of file class.bin.nodejs.php.

◆ LOCAL_CFG_VARS

const LOCAL_CFG_VARS = 'nodejsVars'

Configuration key for the Node.js variables file.

Definition at line 66 of file class.bin.nodejs.php.

◆ ROOT_CFG_ENABLE

const ROOT_CFG_ENABLE = 'nodejsEnable'

Configuration key for enabling the Node.js module.

Definition at line 53 of file class.bin.nodejs.php.

◆ ROOT_CFG_VERSION

const ROOT_CFG_VERSION = 'nodejsVersion'

Configuration key for the Node.js version.

Definition at line 57 of file class.bin.nodejs.php.


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