Bearsampp 2026.9.23
Loading...
Searching...
No Matches
Registry Class Reference

Public Member Functions

 __construct ()
 deleteValue ($key, $subkey, $entry)
 exists ($key, $subkey, $entry=null)
 getAppBinsRegKey ($fromRegistry=true)
 getAppPathRegKey ()
 getLatestError ()
 getProcessorRegKey ()
 getSysPathRegKey ()
 getValue ($key, $subkey, $entry=null)
 setAppBinsRegKey ($value)
 setAppPathRegKey ($value)
 setExpandStringValue ($key, $subkey, $entry, $value)
 setStringValue ($key, $subkey, $entry, $value)
 setSysPathRegKey ($value)

Data Fields

const APP_BINS_REG_ENTRY = 'BEARSAMPP_BINS'
const APP_PATH_REG_ENTRY = 'BEARSAMPP_PATH'
const END_PROCESS_STR = 'FINISHED!'
const ENV_KEY = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
const HKEY_CLASSES_ROOT = 'HKCR'
const HKEY_CURRENT_USER = 'HKCU'
const HKEY_LOCAL_MACHINE = 'HKLM'
const HKEY_USERS = 'HKEY_USERS'
const PROCESSOR_REG_ENTRY = 'Identifier'
const PROCESSOR_REG_SUBKEY = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0'
const REG_BINARY = 'REG_BINARY'
const REG_DWORD = 'REG_DWORD'
const REG_ERROR_ENTRY = 'REG_ERROR_ENTRY'
const REG_ERROR_SET = 'REG_ERROR_SET'
const REG_EXPAND_SZ = 'REG_EXPAND_SZ'
const REG_MULTI_SZ = 'REG_MULTI_SZ'
const REG_NO_ERROR = 'REG_NO_ERROR'
const REG_SZ = 'REG_SZ'
const SYSPATH_REG_ENTRY = 'Path'

Private Member Functions

 setValue ($key, $subkey, $entry, $value, $type)
 writeLog ($log)

Private Attributes

 $latestError

Detailed Description

Class Registry

This class provides methods to interact with the Windows Registry using COM. It includes functionalities to check the existence of registry keys, get and set values, and delete registry entries. The class also logs operations and errors.

Definition at line 17 of file class.registry.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Registry constructor. Initializes the Registry class and logs the initialization.

Definition at line 57 of file class.registry.php.

58 {
59 Log::initClass($this);
60 $this->latestError = null;
61 }
static initClass($classInstance)

References Log\initClass().

Here is the call graph for this function:

Member Function Documentation

◆ deleteValue()

deleteValue ( $key,
$subkey,
$entry )

Deletes a registry entry.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
Returns
bool True if the entry was deleted successfully, false otherwise.

Definition at line 167 of file class.registry.php.

168 {
169 $this->writeLog('delete');
170
171 return $this->setValue($key, $subkey, $entry, null, 'DeleteValue');
172 }
setValue($key, $subkey, $entry, $value, $type)

References setValue(), and writeLog().

Here is the call graph for this function:

◆ exists()

exists ( $key,
$subkey,
$entry = null )

Checks if a registry key or entry exists. Now uses Win32Native COM methods instead of VBScript.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string | null$entryThe entry name (optional).
Returns
bool True if the key or entry exists, false otherwise.

Definition at line 84 of file class.registry.php.

85 {
86 $this->writeLog('Exists ' . $key . '\\' . $subkey . '\\' . $entry);
87
88 // Use Win32Native COM implementation
89 $result = Win32Native::registryExists($key, $subkey, $entry);
90
91 $this->writeLog('-> result: ' . ($result ? '1' : '0'));
92
93 return $result;
94 }
$result
static registryExists($hive, $key, $value=null)

References $result, Win32Native\registryExists(), and writeLog().

Here is the call graph for this function:

◆ getAppBinsRegKey()

getAppBinsRegKey ( $fromRegistry = true)

Retrieves or generates the application binaries registry key.

Parameters
bool$fromRegistryDetermines whether to retrieve the key from the registry or generate it.
Returns
string|false Returns the application binaries registry key, or false on error.

Definition at line 248 of file class.registry.php.

249 {
250 if ($fromRegistry) {
251 $value = $this->getValue(
252 self::HKEY_LOCAL_MACHINE,
253 self::ENV_KEY,
254 self::APP_BINS_REG_ENTRY
255 );
256 Log::debug('App reg key from registry: ' . $value);
257 } else {
258 global $bearsamppBins, $bearsamppTools;
259 $value = '';
260 if ($bearsamppBins->getApache()->isEnable()) {
261 $value .= Path::getModuleSymlinkPath($bearsamppBins->getApache()) . '/bin;';
262 }
263 if ($bearsamppBins->getPhp()->isEnable()) {
264 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . ';';
265 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . '/pear;';
266 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . '/deps;';
267 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . '/imagick;';
268 }
269 if ($bearsamppBins->getNodejs()->isEnable()) {
270 $value .= Path::getModuleSymlinkPath($bearsamppBins->getNodejs()) . ';';
271 }
272 if ($bearsamppBins->getMysql()->isEnable()) {
273 $value .= Path::getModuleSymlinkPath($bearsamppBins->getMysql()) . '/bin;';
274 }
275 if ($bearsamppBins->getMariadb()->isEnable()) {
276 $value .= Path::getModuleSymlinkPath($bearsamppBins->getMariadb()) . '/bin;';
277 }
278 if ($bearsamppBins->getPostgresql()->isEnable()) {
279 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPostgresql()) . '/bin;';
280 }
281 if ($bearsamppTools->getComposer()->isEnable()) {
282 $value .= Path::getModuleSymlinkPath($bearsamppTools->getComposer()) . ';';
283 $value .= Path::getModuleSymlinkPath($bearsamppTools->getComposer()) . '/vendor/bin;';
284 }
285 if ($bearsamppTools->getGhostscript()->isEnable()) {
286 $value .= Path::getModuleSymlinkPath($bearsamppTools->getGhostscript()) . '/bin;';
287 }
288 if ($bearsamppTools->getGit()->isEnable()) {
289 $value .= Path::getModuleSymlinkPath($bearsamppTools->getGit()) . '/bin;';
290 }
291 if ($bearsamppTools->getNgrok()->isEnable()) {
292 $value .= Path::getModuleSymlinkPath($bearsamppTools->getNgrok()) . ';';
293 }
294 if ($bearsamppTools->getPerl()->isEnable()) {
295 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPerl()) . '/perl/site/bin;';
296 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPerl()) . '/perl/bin;';
297 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPerl()) . '/c/bin;';
298 }
299 if ($bearsamppTools->getPython()->isEnable()) {
300 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPython()) . '/bin;';
301 }
302 if ($bearsamppTools->getRuby()->isEnable()) {
303 $value .= Path::getModuleSymlinkPath($bearsamppTools->getRuby()) . '/bin;';
304 }
305 $value = Path::formatWindowsPath($value);
306 Log::debug('Generated app bins reg key: ' . $value);
307 }
308
309 return $value;
310 }
global $bearsamppBins
static debug($data, $file=null)
static formatWindowsPath($path)
static getModuleSymlinkPath($module)
getValue($key, $subkey, $entry=null)

References $bearsamppBins, Log\debug(), Path\formatWindowsPath(), Path\getModuleSymlinkPath(), and getValue().

Here is the call graph for this function:

◆ getAppPathRegKey()

getAppPathRegKey ( )

Retrieves the application path from the registry.

Returns
mixed The value of the application path registry key or false on error.

Definition at line 334 of file class.registry.php.

335 {
336 return $this->getValue(
337 self::HKEY_LOCAL_MACHINE,
338 self::ENV_KEY,
339 self::APP_PATH_REG_ENTRY
340 );
341 }

References getValue().

Here is the call graph for this function:

◆ getLatestError()

getLatestError ( )

Retrieves the latest error message.

Returns
string|null The latest error message, or null if no error occurred.

Definition at line 410 of file class.registry.php.

411 {
412 return $this->latestError;
413 }

References $latestError.

◆ getProcessorRegKey()

getProcessorRegKey ( )

Retrieves the processor identifier from the registry.

Returns
mixed The value of the processor identifier registry key or false on error.

Definition at line 396 of file class.registry.php.

397 {
398 return $this->getValue(
399 self::HKEY_LOCAL_MACHINE,
400 self::PROCESSOR_REG_SUBKEY,
401 self::PROCESSOR_REG_ENTRY
402 );
403 }

References getValue().

Here is the call graph for this function:

◆ getSysPathRegKey()

getSysPathRegKey ( )

Retrieves the system path from the registry.

Returns
mixed The value of the system path registry key or false on error.

Definition at line 365 of file class.registry.php.

366 {
367 return $this->getValue(
368 self::HKEY_LOCAL_MACHINE,
369 self::ENV_KEY,
370 self::SYSPATH_REG_ENTRY
371 );
372 }

References getValue().

Here is the call graph for this function:

◆ getValue()

getValue ( $key,
$subkey,
$entry = null )

Retrieves the value of a registry entry. Now uses Win32Native COM methods instead of VBScript.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string | null$entryThe entry name (optional).
Returns
mixed The value of the registry entry, or false on error.

Definition at line 106 of file class.registry.php.

107 {
108 global $bearsamppLang;
109
110 $this->latestError = null;
111
112 $this->writeLog('GetValue ' . $key . '\\' . $subkey . '\\' . $entry);
113
114 // Use Win32Native COM implementation
115 $result = Win32Native::registryGetValue($key, $subkey, $entry);
116
117 $this->writeLog('-> result: ' . $result);
118
119 if ($result === null) {
120 $this->latestError = $bearsamppLang->getValue(Lang::ERROR) . ' Registry value not found';
121
122 return false;
123 }
124
125 return $result;
126 }
global $bearsamppLang
const ERROR
static registryGetValue($hive, $key, $value='')

References $bearsamppLang, $result, Lang\ERROR, Win32Native\registryGetValue(), and writeLog().

Referenced by getAppBinsRegKey(), getAppPathRegKey(), getProcessorRegKey(), and getSysPathRegKey().

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

◆ setAppBinsRegKey()

setAppBinsRegKey ( $value)

Sets the application binaries registry key.

Parameters
string$valueThe new value for the application binaries.
Returns
bool True on success, false on failure.

Definition at line 319 of file class.registry.php.

320 {
321 return $this->setStringValue(
322 self::HKEY_LOCAL_MACHINE,
323 self::ENV_KEY,
324 self::APP_BINS_REG_ENTRY,
325 $value
326 );
327 }
setStringValue($key, $subkey, $entry, $value)

References setStringValue().

Here is the call graph for this function:

◆ setAppPathRegKey()

setAppPathRegKey ( $value)

Sets the application path in the registry.

Parameters
string$valueThe new value for the application path.
Returns
bool True on success, false on failure.

Definition at line 350 of file class.registry.php.

351 {
352 return $this->setStringValue(
353 self::HKEY_LOCAL_MACHINE,
354 self::ENV_KEY,
355 self::APP_PATH_REG_ENTRY,
356 $value
357 );
358 }

References setStringValue().

Here is the call graph for this function:

◆ setExpandStringValue()

setExpandStringValue ( $key,
$subkey,
$entry,
$value )

Sets an expanded string value in the registry.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
string$valueThe value to set.
Returns
bool True if the value was set successfully, false otherwise.

Definition at line 153 of file class.registry.php.

154 {
155 return $this->setValue($key, $subkey, $entry, $value, 'SetExpandedStringValue');
156 }

References setValue().

Referenced by setSysPathRegKey().

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

◆ setStringValue()

setStringValue ( $key,
$subkey,
$entry,
$value )

Sets a string value in the registry.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
string$valueThe value to set.
Returns
bool True if the value was set successfully, false otherwise.

Definition at line 138 of file class.registry.php.

139 {
140 return $this->setValue($key, $subkey, $entry, $value, 'SetStringValue');
141 }

References setValue().

Referenced by setAppBinsRegKey(), and setAppPathRegKey().

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

◆ setSysPathRegKey()

setSysPathRegKey ( $value)

Sets the system path in the registry.

Parameters
string$valueThe new value for the system path.
Returns
bool True on success, false on failure.

Definition at line 381 of file class.registry.php.

382 {
383 return $this->setExpandStringValue(
384 self::HKEY_LOCAL_MACHINE,
385 self::ENV_KEY,
386 self::SYSPATH_REG_ENTRY,
387 $value
388 );
389 }
setExpandStringValue($key, $subkey, $entry, $value)

References setExpandStringValue().

Here is the call graph for this function:

◆ setValue()

setValue ( $key,
$subkey,
$entry,
$value,
$type )
private

Sets a value in the registry. Now uses Win32Native COM methods instead of VBScript.

Parameters
string$keyThe root key (e.g., HKEY_LOCAL_MACHINE).
string$subkeyThe subkey path.
string$entryThe entry name.
string | null$valueThe value to set (optional).
string$typeThe type of value to set (e.g., SetStringValue).
Returns
bool True if the value was set successfully, false otherwise.

Definition at line 186 of file class.registry.php.

187 {
188 global $bearsamppLang;
189
190 $this->latestError = null;
191
192 $this->writeLog('SetValue ' . $key . '\\' . $subkey . '\\' . $entry);
193 $this->writeLog('-> value: ' . $value);
194 $this->writeLog('-> type: ' . $type);
195
196 // Map the VBS type to Win32Native registry type
197 $regType = self::REG_SZ; // Default
198 if ($type == 'SetExpandedStringValue') {
199 $regType = self::REG_EXPAND_SZ;
200 } elseif ($type == 'SetStringValue') {
201 $regType = self::REG_SZ;
202 }
203
204 // Handle delete operations
205 if ($type == 'DeleteValue' && !empty($entry)) {
206 // Delete a value
207 $result = Win32Native::registryDeleteValue($key, $subkey, $entry);
208 } elseif ($type == 'DeleteValue' && empty($entry)) {
209 // Delete a key
211 } else {
212 // Set a value
213 $result = Win32Native::registrySetValue($key, $subkey, $entry, $value, $regType);
214 }
215
216 if ($subkey == self::ENV_KEY) {
218 }
219
220 $this->writeLog('-> result: ' . ($result ? 'success' : 'failed'));
221
222 if (!$result) {
223 $this->latestError = $bearsamppLang->getValue(Lang::ERROR) . ' Registry operation failed';
224
225 return false;
226 }
227
228 // Verify the value was set correctly (for set operations)
229 if ($type != 'DeleteValue' && !empty($value)) {
230 $verifyValue = Win32Native::registryGetValue($key, $subkey, $entry);
231 if ($verifyValue != $value) {
232 $this->latestError = sprintf($bearsamppLang->getValue(Lang::REGISTRY_SET_ERROR_TEXT), $value);
233
234 return false;
235 }
236 }
237
238 return true;
239 }
static refreshEnvVars()
const REGISTRY_SET_ERROR_TEXT
static registrySetValue($hive, $key, $value, $data, $type='REG_SZ')
static registryDeleteValue($hive, $key, $value)
static registryDeleteKey($hive, $key)

References $bearsamppLang, $result, Lang\ERROR, Batch\refreshEnvVars(), Lang\REGISTRY_SET_ERROR_TEXT, Win32Native\registryDeleteKey(), Win32Native\registryDeleteValue(), Win32Native\registryGetValue(), Win32Native\registrySetValue(), and writeLog().

Referenced by deleteValue(), setExpandStringValue(), and setStringValue().

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

◆ writeLog()

writeLog ( $log)
private

Writes a log entry.

Parameters
string$logThe log message to write.

Definition at line 68 of file class.registry.php.

69 {
70 global $bearsamppRoot;
72 }
global $bearsamppRoot
static getRegistryLogFilePath($aetrayPath=false)

References $bearsamppRoot, Log\debug(), and Path\getRegistryLogFilePath().

Referenced by deleteValue(), exists(), getValue(), and setValue().

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

Field Documentation

◆ $latestError

$latestError
private

Definition at line 51 of file class.registry.php.

Referenced by getLatestError().

◆ APP_BINS_REG_ENTRY

const APP_BINS_REG_ENTRY = 'BEARSAMPP_BINS'

◆ APP_PATH_REG_ENTRY

const APP_PATH_REG_ENTRY = 'BEARSAMPP_PATH'

Definition at line 42 of file class.registry.php.

Referenced by ActionStartup\checkPathRegKey(), and Batch\refreshEnvVars().

◆ END_PROCESS_STR

const END_PROCESS_STR = 'FINISHED!'

Definition at line 19 of file class.registry.php.

◆ ENV_KEY

const ENV_KEY = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'

Definition at line 36 of file class.registry.php.

◆ HKEY_CLASSES_ROOT

const HKEY_CLASSES_ROOT = 'HKCR'

Definition at line 21 of file class.registry.php.

◆ HKEY_CURRENT_USER

const HKEY_CURRENT_USER = 'HKCU'

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

Referenced by Path\findExecutable().

◆ HKEY_LOCAL_MACHINE

◆ HKEY_USERS

const HKEY_USERS = 'HKEY_USERS'

Definition at line 24 of file class.registry.php.

◆ PROCESSOR_REG_ENTRY

const PROCESSOR_REG_ENTRY = 'Identifier'

Definition at line 49 of file class.registry.php.

◆ PROCESSOR_REG_SUBKEY

const PROCESSOR_REG_SUBKEY = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0'

Definition at line 48 of file class.registry.php.

◆ REG_BINARY

const REG_BINARY = 'REG_BINARY'

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

◆ REG_DWORD

const REG_DWORD = 'REG_DWORD'

Definition at line 29 of file class.registry.php.

◆ REG_ERROR_ENTRY

const REG_ERROR_ENTRY = 'REG_ERROR_ENTRY'

Definition at line 32 of file class.registry.php.

◆ REG_ERROR_SET

const REG_ERROR_SET = 'REG_ERROR_SET'

Definition at line 33 of file class.registry.php.

◆ REG_EXPAND_SZ

const REG_EXPAND_SZ = 'REG_EXPAND_SZ'

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

◆ REG_MULTI_SZ

const REG_MULTI_SZ = 'REG_MULTI_SZ'

Definition at line 30 of file class.registry.php.

◆ REG_NO_ERROR

const REG_NO_ERROR = 'REG_NO_ERROR'

Definition at line 34 of file class.registry.php.

◆ REG_SZ

const REG_SZ = 'REG_SZ'

Definition at line 26 of file class.registry.php.

◆ SYSPATH_REG_ENTRY

const SYSPATH_REG_ENTRY = 'Path'

Definition at line 45 of file class.registry.php.

Referenced by ActionStartup\checkSystemPathRegKey().


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