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

Public Member Functions

 __construct ($rootPath)
 errorHandler ($errno, $errstr, $errfile, $errline)
 getProcs ()
 initErrorHandling ()
 isRoot ()
 register ()
 removeErrorHandling ()

Static Public Member Functions

static clearCaches ()
static ensureModuleLoaded ($module, $timeout=5000)
static getCacheStats ()
static loadApps ()
static loadAppsAsync ()
static loadAppsFiber ()
static loadBins ()
static loadConfig ()
static loadCore ()
static loadHomepage ()
static loadHomepageAsync ()
static loadHomepageFiber ()
static loadLang ()
static loadOpenSsl ()
static loadRegistry ()
static loadRegistryAsync ()
static loadRegistryFiber ()
static loadTools ()
static loadToolsAsync ()
static loadToolsFiber ()
static loadWinbinder ()

Data Fields

 $path
const ERROR_HANDLER = 'errorHandler'

Static Private Member Functions

static debugStringBacktrace ()

Private Attributes

 $isRoot
 $procs
 $procsLoaded = false

Detailed Description

Class Root

This class represents the root of the Bearsampp application. It handles the initialization, configuration, and management of various components and settings within the application.

Definition at line 16 of file class.root.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $rootPath)

Constructs a Root object with the specified root path.

Parameters
string$rootPathThe root path of the application.

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

31 {
32 $this->path = str_replace('\\', '/', rtrim($rootPath, '/\\'));
33 $this->isRoot = $_SERVER['PHP_SELF'] == 'root.php';
34 Path::init(dirname($this->path), $this->path);
35 }
static init($rootPath, $corePath)

References Path\init(), and isRoot().

Here is the call graph for this function:

Member Function Documentation

◆ clearCaches()

clearCaches ( )
static

Clear all configuration caches Used on version upgrade or manual reset

Returns
int Number of cache files deleted

Definition at line 172 of file class.root.php.

172 : int
173 {
174 return CacheManager::clearAll();
175 }

References CacheManager\clearAll().

Referenced by ActionClearFolders\__construct().

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

◆ debugStringBacktrace()

debugStringBacktrace ( )
staticprivate

Generates a debug backtrace string.

Returns
string The debug backtrace.

Definition at line 428 of file class.root.php.

429 {
430 ob_start();
431 debug_print_backtrace();
432 $trace = ob_get_contents();
433 ob_end_clean();
434
435 $trace = preg_replace('/^#0\s+Root::debugStringBacktrace[^\n]*\n/', '', $trace, 1);
436 $trace = preg_replace('/^#1\s+isRoot->errorHandler[^\n]*\n/', '', $trace, 1);
437 $trace = preg_replace_callback('/^#(\d+)/m', 'debugStringPregReplace', $trace);
438
439 return $trace;
440 }

Referenced by errorHandler().

Here is the caller graph for this function:

◆ ensureModuleLoaded()

ensureModuleLoaded ( $module,
$timeout = 5000 )
static

Ensures a module is loaded, waiting if it's still loading asynchronously. Safe to call for modules that may be loading in background. Supports both fiber-based and deferred loading mechanisms.

Parameters
string$moduleThe module name (use ModuleLoader constants)
int$timeoutMaximum wait time in milliseconds
Returns
bool True if module loaded successfully

Definition at line 144 of file class.root.php.

145 {
146 // Try Fiber loader first (if available on PHP 8.1+)
148 return FiberModuleLoader::waitForModule($module, $timeout);
149 }
150
151 // Fallback to deferred loading
152 return ModuleLoader::waitForModule($module, $timeout);
153 }
static waitForModule(string $module, int $timeout=5000)
static waitForModule($module, $timeout=5000)

References FiberModuleLoader\isAvailable(), FiberModuleLoader\waitForModule(), and ModuleLoader\waitForModule().

Here is the call graph for this function:

◆ errorHandler()

errorHandler ( $errno,
$errstr,
$errfile,
$errline )

Handles errors and logs them to the error log file.

Parameters
int$errnoThe level of the error raised.
string$errstrThe error message.
string$errfileThe filename that the error was raised in.
int$errlineThe line number the error was raised at.

Definition at line 385 of file class.root.php.

386 {
387 if (!(error_reporting() & $errno)) {
388 return;
389 }
390
391 $errfile = Path::formatUnixPath($errfile);
392 $errfile = str_replace(Path::getRootPath(), '', $errfile);
393
394 if (!defined('E_DEPRECATED')) {
395 define('E_DEPRECATED', 8192);
396 }
397
398 $errNames = array(
399 E_ERROR => 'E_ERROR',
400 E_WARNING => 'E_WARNING',
401 E_PARSE => 'E_PARSE',
402 E_NOTICE => 'E_NOTICE',
403 E_CORE_ERROR => 'E_CORE_ERROR',
404 E_CORE_WARNING => 'E_CORE_WARNING',
405 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
406 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
407 E_USER_ERROR => 'E_USER_ERROR',
408 E_USER_WARNING => 'E_USER_WARNING',
409 E_USER_NOTICE => 'E_USER_NOTICE',
410 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
411 E_DEPRECATED => 'E_DEPRECATED',
412 );
413
414 $content = '[' . date('Y-m-d H:i:s', time()) . '] ';
415 $content .= $errNames[$errno] . ' ';
416 $content .= $errstr . ' in ' . $errfile;
417 $content .= ' on line ' . $errline . PHP_EOL;
418 $content .= self::debugStringBacktrace() . PHP_EOL;
419
420 @file_put_contents(Path::getErrorLogFilePath(), $content, FILE_APPEND);
421 }
static getRootPath($aetrayPath=false)
static formatUnixPath($path)
static getErrorLogFilePath($aetrayPath=false)
static debugStringBacktrace()
if(!extension_loaded('winbinder')) if(!dl('php_winbinder.dll')) trigger_error("WinBinder extension could not be loaded.\n" E_USER_ERROR
Definition winbinder.php:14

References debugStringBacktrace(), E_USER_ERROR, Path\formatUnixPath(), Path\getErrorLogFilePath(), and Path\getRootPath().

Here is the call graph for this function:

◆ getCacheStats()

getCacheStats ( )
static

Get cache manager statistics Useful for monitoring warm start performance

Returns
array Cache statistics

Definition at line 161 of file class.root.php.

161 : array
162 {
163 return CacheManager::getStats();
164 }

References CacheManager\getStats().

Here is the call graph for this function:

◆ getProcs()

getProcs ( )

Retrieves the list of processes. Lazy loads process list only when accessed.

Returns
array The list of processes.

Definition at line 124 of file class.root.php.

125 {
126 if (!$this->procsLoaded && $this->isRoot()) {
127 $this->procs = Win32Ps::getListProcs();
128 $this->procsLoaded = true;
129 }
130
131 return $this->procs;
132 }
static getListProcs()

References $procs, Win32Ps\getListProcs(), and isRoot().

Here is the call graph for this function:

◆ initErrorHandling()

initErrorHandling ( )

Initializes error handling settings for the application.

Definition at line 99 of file class.root.php.

100 {
101 error_reporting(-1);
102 ini_set('error_log', Path::getErrorLogFilePath());
103 ini_set('display_errors', '1');
104 set_error_handler(array($this, self::ERROR_HANDLER));
105 }

References Path\getErrorLogFilePath().

Referenced by register().

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

◆ isRoot()

isRoot ( )

Checks if the current script is executed from the root path.

Returns
bool True if executed from the root, false otherwise.

Definition at line 182 of file class.root.php.

183 {
184 return $this->isRoot;
185 }

References $isRoot.

Referenced by __construct(), and getProcs().

Here is the caller graph for this function:

◆ loadApps()

loadApps ( )
static

Loads the apps components of the application.

Definition at line 246 of file class.root.php.

247 {
248 global $bearsamppApps;
249 $bearsamppApps = new Apps();
250 }

◆ loadAppsAsync()

loadAppsAsync ( )
static

Loads the apps components asynchronously. Apps module loads in background without blocking main thread.

Definition at line 297 of file class.root.php.

298 {
300 global $bearsamppApps;
301 $bearsamppApps = new Apps();
302 });
303 }
static loadAsync($module, callable $loader)

References ModuleLoader\APPS, and ModuleLoader\loadAsync().

Referenced by register().

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

◆ loadAppsFiber()

loadAppsFiber ( )
static

Loads the apps components in a Fiber (true async, PHP 8.1+) Apps module loads concurrently with main startup.

Definition at line 345 of file class.root.php.

346 {
348 global $bearsamppApps;
349 $bearsamppApps = new Apps();
350 });
351 }
static loadInFiber(string $module, callable $loader, int $timeout=5000)

References ModuleLoader\APPS, and FiberModuleLoader\loadInFiber().

Referenced by register().

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

◆ loadBins()

loadBins ( )
static

Loads the binary components of the application.

Definition at line 226 of file class.root.php.

227 {
228 global $bearsamppBins;
229 $bearsamppBins = new Bins();
230 }
global $bearsamppBins

References $bearsamppBins.

Referenced by register().

Here is the caller graph for this function:

◆ loadConfig()

loadConfig ( )
static

Loads the configuration settings of the application.

Definition at line 199 of file class.root.php.

200 {
201 global $bearsamppConfig;
202 $bearsamppConfig = new Config();
203 }
global $bearsamppConfig
Definition homepage.php:46

References $bearsamppConfig.

Referenced by ActionSwitchVersion\processWindow(), and register().

Here is the caller graph for this function:

◆ loadCore()

loadCore ( )
static

Loads the core components of the application.

Definition at line 190 of file class.root.php.

191 {
192 global $bearsamppCore;
193 $bearsamppCore = new Core();
194 }
global $bearsamppCore

References $bearsamppCore.

Referenced by register().

Here is the caller graph for this function:

◆ loadHomepage()

loadHomepage ( )
static

Loads the homepage settings of the application.

Definition at line 275 of file class.root.php.

276 {
277 global $bearsamppHomepage;
278 $bearsamppHomepage = new Homepage();
279 }
global $bearsamppHomepage
Definition homepage.php:46

References $bearsamppHomepage.

◆ loadHomepageAsync()

loadHomepageAsync ( )
static

Loads the homepage settings asynchronously. Homepage is for UI display, can load in background.

Definition at line 321 of file class.root.php.

322 {
324 global $bearsamppHomepage;
325 $bearsamppHomepage = new Homepage();
326 });
327 }

References $bearsamppHomepage, ModuleLoader\HOMEPAGE, and ModuleLoader\loadAsync().

Referenced by register().

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

◆ loadHomepageFiber()

loadHomepageFiber ( )
static

Loads the homepage settings in a Fiber (true async, PHP 8.1+) Homepage is for UI display, loads concurrently.

Definition at line 369 of file class.root.php.

370 {
372 global $bearsamppHomepage;
373 $bearsamppHomepage = new Homepage();
374 });
375 }

References $bearsamppHomepage, ModuleLoader\HOMEPAGE, and FiberModuleLoader\loadInFiber().

Referenced by register().

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

◆ loadLang()

loadLang ( )
static

Loads the language settings of the application.

Definition at line 208 of file class.root.php.

209 {
210 global $bearsamppLang;
211 $bearsamppLang = new LangProc();
212 }
global $bearsamppLang

References $bearsamppLang.

Referenced by register().

Here is the caller graph for this function:

◆ loadOpenSsl()

loadOpenSsl ( )
static

Loads the OpenSSL settings of the application.

Definition at line 217 of file class.root.php.

218 {
219 global $bearsamppOpenSsl;
220 $bearsamppOpenSsl = new OpenSsl();
221 }

Referenced by register().

Here is the caller graph for this function:

◆ loadRegistry()

loadRegistry ( )
static

Loads the registry settings of the application.

Definition at line 266 of file class.root.php.

267 {
268 global $bearsamppRegistry;
269 $bearsamppRegistry = new Registry();
270 }

◆ loadRegistryAsync()

loadRegistryAsync ( )
static

Loads the registry settings asynchronously. Registry operations are slow (COM), loads in background.

Definition at line 309 of file class.root.php.

310 {
312 global $bearsamppRegistry;
313 $bearsamppRegistry = new Registry();
314 });
315 }

References ModuleLoader\loadAsync(), and ModuleLoader\REGISTRY.

Referenced by register().

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

◆ loadRegistryFiber()

loadRegistryFiber ( )
static

Loads the registry settings in a Fiber (true async, PHP 8.1+) Registry operations are slow (COM), loads concurrently.

Definition at line 357 of file class.root.php.

358 {
360 global $bearsamppRegistry;
361 $bearsamppRegistry = new Registry();
362 });
363 }

References FiberModuleLoader\loadInFiber(), and ModuleLoader\REGISTRY.

Referenced by register().

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

◆ loadTools()

loadTools ( )
static

Loads the tools components of the application.

Definition at line 235 of file class.root.php.

236 {
237 global $bearsamppTools;
238 if (!isset($bearsamppTools)) {
239 $bearsamppTools = new Tools();
240 }
241 }

Referenced by Win32Service\create().

Here is the caller graph for this function:

◆ loadToolsAsync()

loadToolsAsync ( )
static

Loads the tools components asynchronously. Tools module loads in background without blocking main thread.

Definition at line 285 of file class.root.php.

286 {
288 global $bearsamppTools;
289 $bearsamppTools = new Tools();
290 });
291 }

References ModuleLoader\loadAsync(), and ModuleLoader\TOOLS.

Referenced by register().

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

◆ loadToolsFiber()

loadToolsFiber ( )
static

Loads the tools components in a Fiber (true async, PHP 8.1+) Tools module loads concurrently with main startup.

Definition at line 333 of file class.root.php.

334 {
336 global $bearsamppTools;
337 $bearsamppTools = new Tools();
338 });
339 }

References FiberModuleLoader\loadInFiber(), and ModuleLoader\TOOLS.

Referenced by register().

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

◆ loadWinbinder()

loadWinbinder ( )
static

Loads the Winbinder extension if available.

Definition at line 255 of file class.root.php.

256 {
257 global $bearsamppWinbinder;
258 if (extension_loaded('winbinder')) {
259 $bearsamppWinbinder = new WinBinder();
260 }
261 }

Referenced by register().

Here is the caller graph for this function:

◆ register()

register ( )

Registers the application components and initializes error handling.

Definition at line 40 of file class.root.php.

41 {
42 // Params
43 set_time_limit(0);
44 clearstatcache();
45
46 // Error log
47 $this->initErrorHandling();
48
49 // External classes
50 require_once $this->path . '/classes/class.log.php';
51 require_once $this->path . '/classes/class.util.php';
52 require_once $this->path . '/classes/class.util.string.php';
53 Log::init();
54
55 // Autoloader
56 require_once $this->path . '/classes/class.autoloader.php';
57 $bearsamppAutoloader = new Autoloader();
58 $bearsamppAutoloader->register();
59
60 // Module loaders for async initialization
61 require_once $this->path . '/classes/class.moduleloader.php';
62 require_once $this->path . '/classes/class.cachemanager.php';
63 require_once $this->path . '/classes/class.fibermoduleloader.php';
64
65 // Initialize cache system (disk caching for warm starts)
67
68 // Initialize fiber loader (true async for 8.1+)
69 $useFibers = FiberModuleLoader::init();
70
71 // Load critical modules synchronously (required for main functionality)
78
79 // Load non-critical modules asynchronously (for UI/admin functions)
80 // Uses Fibers if PHP 8.1+, fallback to deferred loading
81 if ($useFibers) {
86 } else {
91 }
92
94 }
static init(string $cacheDir)
static init()
Definition class.log.php:84
static separator()
static getTmpPath($aetrayPath=false)
static loadBins()
static loadRegistryAsync()
static loadOpenSsl()
static loadLang()
static loadRegistryFiber()
static loadWinbinder()
static loadToolsAsync()
static loadToolsFiber()
static loadAppsAsync()
static loadCore()
static loadHomepageAsync()
static loadAppsFiber()
static loadConfig()
static loadHomepageFiber()
initErrorHandling()

References Path\getTmpPath(), CacheManager\init(), FiberModuleLoader\init(), Log\init(), initErrorHandling(), loadAppsAsync(), loadAppsFiber(), loadBins(), loadConfig(), loadCore(), loadHomepageAsync(), loadHomepageFiber(), loadLang(), loadOpenSsl(), loadRegistryAsync(), loadRegistryFiber(), loadToolsAsync(), loadToolsFiber(), loadWinbinder(), and Log\separator().

Here is the call graph for this function:

◆ removeErrorHandling()

removeErrorHandling ( )

Removes the custom error handling, reverting to the default PHP error handling.

Definition at line 110 of file class.root.php.

111 {
112 error_reporting(0);
113 ini_set('error_log', null);
114 ini_set('display_errors', '0');
115 restore_error_handler();
116 }

Field Documentation

◆ $isRoot

$isRoot
private

Definition at line 23 of file class.root.php.

Referenced by isRoot().

◆ $path

$path

Definition at line 20 of file class.root.php.

◆ $procs

$procs
private

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

Referenced by getProcs().

◆ $procsLoaded

$procsLoaded = false
private

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

◆ ERROR_HANDLER

const ERROR_HANDLER = 'errorHandler'

Definition at line 18 of file class.root.php.


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