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

Static Public Member Functions

static isLoaded ($module)
static isLoading ($module)
static loadAsync ($module, callable $loader)
static loadSync ($module, callable $loader)
static markLoaded ($module)
static waitForModule ($module, $timeout=5000)

Data Fields

const APPS = 'apps'
const BINS = 'bins'
const CONFIG = 'config'
const CORE = 'core'
const HOMEPAGE = 'homepage'
const LANG = 'lang'
const OPENSSL = 'openssl'
const REGISTRY = 'registry'
const TOOLS = 'tools'
const WINBINDER = 'winbinder'

Static Private Member Functions

static loadInBackground ($module, callable $loader)

Static Private Attributes

static $loading = array()
static $maxWaitTime = 5000
static $modules = array()

Detailed Description

Class ModuleLoader

Manages asynchronous loading of non-critical modules. Critical modules (Core, Config, Lang, Bins) load synchronously. Non-critical modules (Apps, Tools, Registry, Homepage) load in background.

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

Member Function Documentation

◆ isLoaded()

isLoaded ( $module)
static

Check if a module is loaded

Parameters
string$moduleModule name
Returns
bool True if loaded, false otherwise

Definition at line 149 of file class.moduleloader.php.

150 {
151 return isset(self::$modules[$module]);
152 }

◆ isLoading()

isLoading ( $module)
static

Check if a module is currently loading

Parameters
string$moduleModule name
Returns
bool True if loading, false otherwise

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

162 {
163 return isset(self::$loading[$module]);
164 }

◆ loadAsync()

loadAsync ( $module,
callable $loader )
static

Queue a module for background loading (non-blocking)

Parameters
string$moduleModule name
callable$loaderCallback that loads the module
Returns
void

Definition at line 64 of file class.moduleloader.php.

65 {
66 if (!isset(self::$modules[$module]) && !isset(self::$loading[$module])) {
67 self::$loading[$module] = true;
68 Log::debug('Queuing module for background load: ' . $module);
69
70 // Try to use process for true async, fallback to direct call
71 $pid = self::loadInBackground($module, $loader);
72 if ($pid === false) {
73 // Fallback: load immediately on main thread
74 Log::debug('Background loading unavailable, loading on main thread: ' . $module);
75 call_user_func($loader);
76 unset(self::$loading[$module]);
77 }
78 }
79 }
static debug($data, $file=null)
static loadInBackground($module, callable $loader)

References Log\debug(), and loadInBackground().

Referenced by Root\loadAppsAsync(), Root\loadHomepageAsync(), Root\loadRegistryAsync(), and Root\loadToolsAsync().

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

◆ loadInBackground()

loadInBackground ( $module,
callable $loader )
staticprivate

Attempts to load a module in the background.

PHP has no true async in-process execution here, so the loader callback is invoked directly and the module is marked as loaded.

Parameters
string$moduleModule name
callable$loaderLoader callback
Returns
bool Always true, as loading always completes within this call.

Definition at line 92 of file class.moduleloader.php.

93 {
94 // For simplicity, we'll use direct loading since PHP doesn't have true async
95 // In a production system, you'd use Process Control (pcntl) or threading
96 // But for Windows/CLI safety, we'll just defer the actual initialization
97 call_user_func($loader);
98 unset(self::$loading[$module]);
99
100 return true;
101 }

Referenced by loadAsync().

Here is the caller graph for this function:

◆ loadSync()

loadSync ( $module,
callable $loader )
static

Load a module synchronously (blocking)

Parameters
string$moduleModule name
callable$loaderCallback that loads the module
Returns
void

Definition at line 46 of file class.moduleloader.php.

47 {
48 if (!isset(self::$modules[$module])) {
49 self::$loading[$module] = true;
50 Log::debug('Loading module: ' . $module . ' (synchronous)');
51 call_user_func($loader);
52 unset(self::$loading[$module]);
53 }
54 }

References Log\debug().

Here is the call graph for this function:

◆ markLoaded()

markLoaded ( $module)
static

Mark a module as loaded

Parameters
string$moduleModule name
Returns
void

Definition at line 136 of file class.moduleloader.php.

137 {
138 self::$modules[$module] = true;
139 unset(self::$loading[$module]);
140 }

◆ waitForModule()

waitForModule ( $module,
$timeout = 5000 )
static

Wait for a module to finish loading (blocking) Used when code needs a module that may be loading asynchronously

Parameters
string$moduleModule name
int$timeoutMaximum wait time in milliseconds
Returns
bool True if module loaded, false if timeout

Definition at line 112 of file class.moduleloader.php.

113 {
114 $startTime = microtime(true);
115 $maxWait = $timeout / 1000; // Convert to seconds
116
117 while (isset(self::$loading[$module])) {
118 if ((microtime(true) - $startTime) > $maxWait) {
119 Log::error('Timeout waiting for module: ' . $module);
120
121 return false;
122 }
123 usleep(10000); // Sleep 10ms before checking again
124 }
125
126 return true;
127 }
static error($data, $file=null)

References Log\error().

Referenced by Root\ensureModuleLoaded().

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

Field Documentation

◆ $loading

$loading = array()
staticprivate

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

◆ $maxWaitTime

$maxWaitTime = 5000
staticprivate

Definition at line 25 of file class.moduleloader.php.

◆ $modules

$modules = array()
staticprivate

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

◆ APPS

const APPS = 'apps'

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

Referenced by Root\loadAppsAsync(), and Root\loadAppsFiber().

◆ BINS

const BINS = 'bins'

Definition at line 31 of file class.moduleloader.php.

◆ CONFIG

const CONFIG = 'config'

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

◆ CORE

const CORE = 'core'

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

◆ HOMEPAGE

const HOMEPAGE = 'homepage'

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

Referenced by Root\loadHomepageAsync(), and Root\loadHomepageFiber().

◆ LANG

const LANG = 'lang'

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

◆ OPENSSL

const OPENSSL = 'openssl'

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

◆ REGISTRY

const REGISTRY = 'registry'

Definition at line 35 of file class.moduleloader.php.

Referenced by Root\loadRegistryAsync(), and Root\loadRegistryFiber().

◆ TOOLS

const TOOLS = 'tools'

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

Referenced by Root\loadToolsAsync(), and Root\loadToolsFiber().

◆ WINBINDER

const WINBINDER = 'winbinder'

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


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