Bearsampp 2026.7.28
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 161 of file class.registry.php.

162 {
163 $this->writeLog('delete');
164 return $this->setValue($key, $subkey, $entry, null, 'DeleteValue');
165 }
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 83 of file class.registry.php.

84 {
85 $this->writeLog('Exists ' . $key . '\\' . $subkey . '\\' . $entry);
86
87 // Use Win32Native COM implementation
88 $result = Win32Native::registryExists($key, $subkey, $entry);
89
90 $this->writeLog('-> result: ' . ($result ? '1' : '0'));
91
92 return $result;
93 }
$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 Returns the application binaries registry key.

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

239 {
240 if ($fromRegistry) {
241 $value = $this->getValue(
242 self::HKEY_LOCAL_MACHINE,
243 self::ENV_KEY,
244 self::APP_BINS_REG_ENTRY
245 );
246 Log::debug('App reg key from registry: ' . $value);
247 } else {
248 global $bearsamppBins, $bearsamppTools;
249 $value = '';
250 if ($bearsamppBins->getApache()->isEnable()) {
251 $value .= Path::getModuleSymlinkPath($bearsamppBins->getApache()) . '/bin;';
252 }
253 if ($bearsamppBins->getPhp()->isEnable()) {
254 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . ';';
255 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . '/pear;';
256 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . '/deps;';
257 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPhp()) . '/imagick;';
258 }
259 if ($bearsamppBins->getNodejs()->isEnable()) {
260 $value .= Path::getModuleSymlinkPath($bearsamppBins->getNodejs()) . ';';
261 }
262 if ($bearsamppBins->getMysql()->isEnable()) {
263 $value .= Path::getModuleSymlinkPath($bearsamppBins->getMysql()) . '/bin;';
264 }
265 if ($bearsamppBins->getMariadb()->isEnable()) {
266 $value .= Path::getModuleSymlinkPath($bearsamppBins->getMariadb()) . '/bin;';
267 }
268 if ($bearsamppBins->getPostgresql()->isEnable()) {
269 $value .= Path::getModuleSymlinkPath($bearsamppBins->getPostgresql()) . '/bin;';
270 }
271 if ($bearsamppTools->getComposer()->isEnable()) {
272 $value .= Path::getModuleSymlinkPath($bearsamppTools->getComposer()) . ';';
273 $value .= Path::getModuleSymlinkPath($bearsamppTools->getComposer()) . '/vendor/bin;';
274 }
275 if ($bearsamppTools->getGhostscript()->isEnable()) {
276 $value .= Path::getModuleSymlinkPath($bearsamppTools->getGhostscript()) . '/bin;';
277 }
278 if ($bearsamppTools->getGit()->isEnable()) {
279 $value .= Path::getModuleSymlinkPath($bearsamppTools->getGit()) . '/bin;';
280 }
281 if ($bearsamppTools->getNgrok()->isEnable()) {
282 $value .= Path::getModuleSymlinkPath($bearsamppTools->getNgrok()) . ';';
283 }
284 if ($bearsamppTools->getPerl()->isEnable()) {
285 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPerl()) . '/perl/site/bin;';
286 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPerl()) . '/perl/bin;';
287 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPerl()) . '/c/bin;';
288 }
289 if ($bearsamppTools->getPython()->isEnable()) {
290 $value .= Path::getModuleSymlinkPath($bearsamppTools->getPython()) . '/bin;';
291 }
292 if ($bearsamppTools->getRuby()->isEnable()) {
293 $value .= Path::getModuleSymlinkPath($bearsamppTools->getRuby()) . '/bin;';
294 }
295 $value = Path::formatWindowsPath($value);
296 Log::debug('Generated app bins reg key: ' . $value);
297 }
298
299 return $value;
300 }
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 324 of file class.registry.php.

325 {
326 return $this->getValue(
327 self::HKEY_LOCAL_MACHINE,
328 self::ENV_KEY,
329 self::APP_PATH_REG_ENTRY
330 );
331 }

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 400 of file class.registry.php.

401 {
402 return $this->latestError;
403 }

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 386 of file class.registry.php.

387 {
388 return $this->getValue(
389 self::HKEY_LOCAL_MACHINE,
390 self::PROCESSOR_REG_SUBKEY,
391 self::PROCESSOR_REG_ENTRY
392 );
393 }

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 355 of file class.registry.php.

356 {
357 return $this->getValue(
358 self::HKEY_LOCAL_MACHINE,
359 self::ENV_KEY,
360 self::SYSPATH_REG_ENTRY
361 );
362 }

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 104 of file class.registry.php.

105 {
106 global $bearsamppLang;
107
108 $this->latestError = null;
109
110 $this->writeLog('GetValue ' . $key . '\\' . $subkey . '\\' . $entry);
111
112 // Use Win32Native COM implementation
113 $result = Win32Native::registryGetValue($key, $subkey, $entry);
114
115 $this->writeLog('-> result: ' . $result);
116
117 if ($result === null) {
118 $this->latestError = $bearsamppLang->getValue(Lang::ERROR) . ' Registry value not found';
119 return false;
120 }
121
122 return $result;
123 }
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 309 of file class.registry.php.

310 {
311 return $this->setStringValue(
312 self::HKEY_LOCAL_MACHINE,
313 self::ENV_KEY,
314 self::APP_BINS_REG_ENTRY,
315 $value
316 );
317 }
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 340 of file class.registry.php.

341 {
342 return $this->setStringValue(
343 self::HKEY_LOCAL_MACHINE,
344 self::ENV_KEY,
345 self::APP_PATH_REG_ENTRY,
346 $value
347 );
348 }

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 148 of file class.registry.php.

149 {
150 return $this->setValue($key, $subkey, $entry, $value, 'SetExpandedStringValue');
151 }

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 134 of file class.registry.php.

135 {
136 return $this->setValue($key, $subkey, $entry, $value, 'SetStringValue');
137 }

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 371 of file class.registry.php.

372 {
373 return $this->setExpandStringValue(
374 self::HKEY_LOCAL_MACHINE,
375 self::ENV_KEY,
376 self::SYSPATH_REG_ENTRY,
377 $value
378 );
379 }
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 178 of file class.registry.php.

179 {
180 global $bearsamppLang;
181
182 $this->latestError = null;
183
184 $this->writeLog('SetValue ' . $key . '\\' . $subkey . '\\' . $entry);
185 $this->writeLog('-> value: ' . $value);
186 $this->writeLog('-> type: ' . $type);
187
188 // Map the VBS type to Win32Native registry type
189 $regType = self::REG_SZ; // Default
190 if ($type == 'SetExpandedStringValue') {
191 $regType = self::REG_EXPAND_SZ;
192 } elseif ($type == 'SetStringValue') {
193 $regType = self::REG_SZ;
194 }
195
196 // Handle delete operations
197 if ($type == 'DeleteValue' && !empty($entry)) {
198 // Delete a value
199 $result = Win32Native::registryDeleteValue($key, $subkey, $entry);
200 } elseif ($type == 'DeleteValue' && empty($entry)) {
201 // Delete a key
203 } else {
204 // Set a value
205 $result = Win32Native::registrySetValue($key, $subkey, $entry, $value, $regType);
206 }
207
208 if ($subkey == self::ENV_KEY) {
210 }
211
212 $this->writeLog('-> result: ' . ($result ? 'success' : 'failed'));
213
214 if (!$result) {
215 $this->latestError = $bearsamppLang->getValue(Lang::ERROR) . ' Registry operation failed';
216 return false;
217 }
218
219 // Verify the value was set correctly (for set operations)
220 if ($type != 'DeleteValue' && !empty($value)) {
221 $verifyValue = Win32Native::registryGetValue($key, $subkey, $entry);
222 if ($verifyValue != $value) {
223 $this->latestError = sprintf($bearsamppLang->getValue(Lang::REGISTRY_SET_ERROR_TEXT), $value);
224 return false;
225 }
226 }
227
228 return true;
229 }
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.

◆ HKEY_LOCAL_MACHINE

const HKEY_LOCAL_MACHINE = 'HKLM'

◆ 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: