2024.8.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 ()
 
 getCurrentPath ()
 
 getId ()
 
 getName ()
 
 getRelease ()
 
 getRootPath ()
 
 getSymlinkPath ()
 
 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
const BUNDLE_RELEASE = 'bundleRelease'
 

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

- Protected Attributes inherited from Module
 $bearsamppConf
 
 $bearsamppConfRaw
 
 $currentPath
 
 $enable
 
 $name
 
 $release = 'N/A'
 
 $rootPath
 
 $symlinkPath
 
 $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:

  • ROOT_CFG_ENABLE: Configuration key for enabling the Node.js module.
  • ROOT_CFG_VERSION: Configuration key for the Node.js version.
  • LOCAL_CFG_EXE: Configuration key for the Node.js executable.
  • LOCAL_CFG_VARS: Configuration key for the Node.js variables.
  • LOCAL_CFG_NPM: Configuration key for the npm executable.
  • LOCAL_CFG_LAUNCH: Configuration key for the Node.js launch script.
  • LOCAL_CFG_CONF: Configuration key for the Node.js configuration file.

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

BinNodejs::__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 71 of file class.bin.nodejs.php.

71 {
72 Util::logInitClass($this);
73 $this->reload($id, $type);
74 }
reload($id=null, $type=null)
static logInitClass($classInstance)

References Module\$id, Module\$type, Util\logInitClass(), and reload().

Member Function Documentation

◆ getConf()

BinNodejs::getConf ( )

Retrieves the configuration file path for Node.js.

Returns
string The configuration file path.

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

248 {
249 return $this->conf;
250 }

References $conf.

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ getExe()

BinNodejs::getExe ( )

Retrieves the executable path for Node.js.

Returns
string The executable path.

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

239 {
240 return $this->exe;
241 }

References $exe.

◆ getLaunch()

BinNodejs::getLaunch ( )

Retrieves the launch script path for Node.js.

Returns
string The launch script path.

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

275 {
276 return $this->launch;
277 }

References $launch.

◆ getNpm()

BinNodejs::getNpm ( )

Retrieves the npm executable path for Node.js.

Returns
string The npm executable path.

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

266 {
267 return $this->npm;
268 }

References $npm.

◆ getVars()

BinNodejs::getVars ( )

Retrieves the variables file path for Node.js.

Returns
string The variables file path.

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

257 {
258 return $this->vars;
259 }

References $vars.

◆ reload()

BinNodejs::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 82 of file class.bin.nodejs.php.

82 {
85
86 $this->name = $bearsamppLang->getValue(Lang::NODEJS);
87 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
88 parent::reload($id, $type);
89
90 $this->enable = $this->enable && $bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
91
92 if ($this->bearsamppConfRaw !== false) {
93 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
94 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
95 $this->vars = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_VARS];
96 $this->npm = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_NPM];
97 $this->launch = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_LAUNCH];
98 }
99
100 if (!$this->enable) {
101 Util::logInfo($this->name . ' is not enabled!');
102 return;
103 }
104 if (!is_dir($this->currentPath)) {
105 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
106 return;
107 }
108 if (!is_dir($this->symlinkPath)) {
109 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
110 return;
111 }
112 if (!is_file($this->bearsamppConf)) {
113 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
114 return;
115 }
116 if (!is_file($this->exe)) {
117 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
118 }
119 if (!is_file($this->conf)) {
120 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
121 }
122 if (!is_file($this->vars)) {
123 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->vars));
124 }
125 if (!is_file($this->npm)) {
126 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->npm));
127 }
128 if (!is_file($this->launch)) {
129 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->launch));
130 }
131 }
global $bearsamppLang
const LOCAL_CFG_LAUNCH
const ERROR_FILE_NOT_FOUND
const NODEJS
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
static logReloadClass($classInstance)
static logError($data, $file=null)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26

References $bearsamppConfig, $bearsamppLang, Module\$id, Module\$type, Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, LOCAL_CFG_CONF, LOCAL_CFG_EXE, LOCAL_CFG_LAUNCH, LOCAL_CFG_NPM, LOCAL_CFG_VARS, Util\logError(), Util\logInfo(), Util\logReloadClass(), and Lang\NODEJS.

Referenced by __construct(), and setVersion().

+ Here is the caller graph for this function:

◆ setEnable()

BinNodejs::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 215 of file class.bin.nodejs.php.

215 {
216 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
217
218 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
219 Util::logDebug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
220 if ($showWindow) {
221 $bearsamppWinbinder->messageBoxError(
222 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
223 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
224 );
225 }
226 $enabled = Config::DISABLED;
227 }
228
229 Util::logInfo($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
230 $this->enable = $enabled == Config::ENABLED;
231 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
232 }
const DISABLED
const ENABLED
const ENABLE_TITLE
const ENABLE_BUNDLE_NOT_EXIST
static logDebug($data, $file=null)

References $bearsamppConfig, $bearsamppLang, Config\DISABLED, Lang\ENABLE_BUNDLE_NOT_EXIST, Lang\ENABLE_TITLE, Config\ENABLED, Module\getName(), Module\getVersion(), Util\logDebug(), and Util\logInfo().

◆ setVersion()

BinNodejs::setVersion ( $version)

Sets the version of the module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

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

202 {
203 global $bearsamppConfig;
204 $this->version = $version;
205 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
206 $this->reload();
207 }

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

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ switchVersion()

BinNodejs::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 140 of file class.bin.nodejs.php.

140 {
141 Util::logDebug('Switch ' . $this->name . ' version to ' . $version);
142 return $this->updateConfig($version, 0, $showWindow);
143 }
updateConfig($version=null, $sub=0, $showWindow=false)

References Module\$version, Util\logDebug(), and updateConfig().

◆ updateConfig()

BinNodejs::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 153 of file class.bin.nodejs.php.

153 {
154 global $bearsamppLang, $bearsamppWinbinder;
155
156 if (!$this->enable) {
157 return true;
158 }
159
160 $version = $version == null ? $this->version : $version;
161 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
162
163 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
164
165 $conf = str_replace('nodejs' . $this->getVersion(), 'nodejs' . $version, $this->getConf());
166 $bearsamppConf = str_replace('nodejs' . $this->getVersion(), 'nodejs' . $version, $this->bearsamppConf);
167
168 if (!file_exists($conf) || !file_exists($bearsamppConf)) {
169 Util::logError('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
170 if ($showWindow) {
171 $bearsamppWinbinder->messageBoxError(
172 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
173 $boxTitle
174 );
175 }
176 return false;
177 }
178
179 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
180 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
181 Util::logError('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
182 if ($showWindow) {
183 $bearsamppWinbinder->messageBoxError(
184 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
185 $boxTitle
186 );
187 }
188 return false;
189 }
190
191 // bearsampp.conf
192 $this->setVersion($version);
193
194 return true;
195 }
setVersion($version)
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE
const BEARSAMPP_CONF_MALFORMED_ERROR

References Module\$bearsamppConf, Module\$bearsamppConfRaw, $bearsamppLang, $conf, Module\$version, Lang\BEARSAMPP_CONF_MALFORMED_ERROR, Lang\BEARSAMPP_CONF_NOT_FOUND_ERROR, getConf(), Module\getName(), Module\getVersion(), Util\logDebug(), Util\logError(), setVersion(), and Lang\SWITCH_VERSION_TITLE.

Referenced by switchVersion().

+ Here is the caller graph for this function:

Field Documentation

◆ $conf

BinNodejs::$conf
private

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

Referenced by getConf(), and updateConfig().

◆ $exe

BinNodejs::$exe
private

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

Referenced by getExe().

◆ $launch

BinNodejs::$launch
private

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

Referenced by getLaunch().

◆ $npm

BinNodejs::$npm
private

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

Referenced by getNpm().

◆ $vars

BinNodejs::$vars
private

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

Referenced by getVars().

◆ LOCAL_CFG_CONF

const BinNodejs::LOCAL_CFG_CONF = 'nodejsConf'

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

Referenced by reload().

◆ LOCAL_CFG_EXE

const BinNodejs::LOCAL_CFG_EXE = 'nodejsExe'

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

Referenced by reload().

◆ LOCAL_CFG_LAUNCH

const BinNodejs::LOCAL_CFG_LAUNCH = 'nodejsLaunch'

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

Referenced by reload().

◆ LOCAL_CFG_NPM

const BinNodejs::LOCAL_CFG_NPM = 'nodejsNpm'

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

Referenced by reload().

◆ LOCAL_CFG_VARS

const BinNodejs::LOCAL_CFG_VARS = 'nodejsVars'

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

Referenced by reload().

◆ ROOT_CFG_ENABLE

const BinNodejs::ROOT_CFG_ENABLE = 'nodejsEnable'

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

◆ ROOT_CFG_VERSION

const BinNodejs::ROOT_CFG_VERSION = 'nodejsVersion'

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


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