Bearsampp 2026.7.11
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 170 of file class.root.php.

170 : int
171 {
172 return CacheManager::clearAll();
173 }

References CacheManager\clearAll().

Here is the call graph for this function:

◆ debugStringBacktrace()

debugStringBacktrace ( )
staticprivate

Generates a debug backtrace string.

Returns
string The debug backtrace.

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

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

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 142 of file class.root.php.

143 {
144 // Try Fiber loader first (if available on PHP 8.1+)
146 return FiberModuleLoader::waitForModule($module, $timeout);
147 }
148
149 // Fallback to deferred loading
150 return ModuleLoader::waitForModule($module, $timeout);
151 }
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 383 of file class.root.php.

384 {
385 if (!(error_reporting() & $errno)) {
386 return;
387 }
388
389 $errfile = Path::formatUnixPath($errfile);
390 $errfile = str_replace(Path::getRootPath(), '', $errfile);
391
392 if (!defined('E_DEPRECATED')) {
393 define('E_DEPRECATED', 8192);
394 }
395
396 $errNames = array(
397 E_ERROR => 'E_ERROR',
398 E_WARNING => 'E_WARNING',
399 E_PARSE => 'E_PARSE',
400 E_NOTICE => 'E_NOTICE',
401 E_CORE_ERROR => 'E_CORE_ERROR',
402 E_CORE_WARNING => 'E_CORE_WARNING',
403 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
404 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
405 E_USER_ERROR => 'E_USER_ERROR',
406 E_USER_WARNING => 'E_USER_WARNING',
407 E_USER_NOTICE => 'E_USER_NOTICE',
408 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
409 E_DEPRECATED => 'E_DEPRECATED',
410 );
411
412 $content = '[' . date('Y-m-d H:i:s', time()) . '] ';
413 $content .= $errNames[$errno] . ' ';
414 $content .= $errstr . ' in ' . $errfile;
415 $content .= ' on line ' . $errline . PHP_EOL;
416 $content .= self::debugStringBacktrace() . PHP_EOL;
417
418 file_put_contents(Path::getErrorLogFilePath(), $content, FILE_APPEND);
419 }
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 159 of file class.root.php.

159 : array
160 {
161 return CacheManager::getStats();
162 }

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 return $this->procs;
131 }
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 180 of file class.root.php.

181 {
182 return $this->isRoot;
183 }

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 244 of file class.root.php.

245 {
246 global $bearsamppApps;
247 $bearsamppApps = new Apps();
248 }

◆ loadAppsAsync()

loadAppsAsync ( )
static

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

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

296 {
298 global $bearsamppApps;
299 $bearsamppApps = new Apps();
300 });
301 }
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 343 of file class.root.php.

344 {
346 global $bearsamppApps;
347 $bearsamppApps = new Apps();
348 });
349 }
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 224 of file class.root.php.

225 {
226 global $bearsamppBins;
227 $bearsamppBins = new Bins();
228 }
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 197 of file class.root.php.

198 {
199 global $bearsamppConfig;
200 $bearsamppConfig = new Config();
201 }
global $bearsamppConfig
Definition homepage.php:41

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 188 of file class.root.php.

189 {
190 global $bearsamppCore;
191 $bearsamppCore = new Core();
192 }
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 273 of file class.root.php.

274 {
275 global $bearsamppHomepage;
276 $bearsamppHomepage = new Homepage();
277 }
global $bearsamppHomepage
Definition homepage.php:41

References $bearsamppHomepage.

◆ loadHomepageAsync()

loadHomepageAsync ( )
static

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

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

320 {
322 global $bearsamppHomepage;
323 $bearsamppHomepage = new Homepage();
324 });
325 }

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 367 of file class.root.php.

368 {
370 global $bearsamppHomepage;
371 $bearsamppHomepage = new Homepage();
372 });
373 }

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 206 of file class.root.php.

207 {
208 global $bearsamppLang;
209 $bearsamppLang = new LangProc();
210 }
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 215 of file class.root.php.

216 {
217 global $bearsamppOpenSsl;
218 $bearsamppOpenSsl = new OpenSsl();
219 }

Referenced by register().

Here is the caller graph for this function:

◆ loadRegistry()

loadRegistry ( )
static

Loads the registry settings of the application.

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

265 {
266 global $bearsamppRegistry;
267 $bearsamppRegistry = new Registry();
268 }

◆ loadRegistryAsync()

loadRegistryAsync ( )
static

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

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

308 {
310 global $bearsamppRegistry;
311 $bearsamppRegistry = new Registry();
312 });
313 }

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

356 {
358 global $bearsamppRegistry;
359 $bearsamppRegistry = new Registry();
360 });
361 }

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 233 of file class.root.php.

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

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 283 of file class.root.php.

284 {
286 global $bearsamppTools;
287 $bearsamppTools = new Tools();
288 });
289 }

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 331 of file class.root.php.

332 {
334 global $bearsamppTools;
335 $bearsamppTools = new Tools();
336 });
337 }

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 253 of file class.root.php.

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

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