Bearsampp 2026.7.11
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 133 of file class.moduleloader.php.

134 {
135 return isset(self::$modules[$module]);
136 }

◆ 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 144 of file class.moduleloader.php.

145 {
146 return isset(self::$loading[$module]);
147 }

◆ 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 57 of file class.moduleloader.php.

58 {
59 if (!isset(self::$modules[$module]) && !isset(self::$loading[$module])) {
60 self::$loading[$module] = true;
61 Log::debug('Queuing module for background load: ' . $module);
62
63 // Try to use process for true async, fallback to direct call
64 $pid = self::loadInBackground($module, $loader);
65 if ($pid === false) {
66 // Fallback: load immediately on main thread
67 Log::debug('Background loading unavailable, loading on main thread: ' . $module);
68 call_user_func($loader);
69 unset(self::$loading[$module]);
70 }
71 }
72 }
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

Attempt to load module in background process

Parameters
string$moduleModule name
callable$loaderLoader callback
Returns
int|false Process ID if successful, false otherwise

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

82 {
83 // For simplicity, we'll use direct loading since PHP doesn't have true async
84 // In a production system, you'd use Process Control (pcntl) or threading
85 // But for Windows/CLI safety, we'll just defer the actual initialization
86 call_user_func($loader);
87 unset(self::$loading[$module]);
88 return true;
89 }

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 40 of file class.moduleloader.php.

41 {
42 if (!isset(self::$modules[$module])) {
43 self::$loading[$module] = true;
44 Log::debug('Loading module: ' . $module . ' (synchronous)');
45 call_user_func($loader);
46 unset(self::$loading[$module]);
47 }
48 }

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 121 of file class.moduleloader.php.

122 {
123 self::$modules[$module] = true;
124 unset(self::$loading[$module]);
125 }

◆ 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 99 of file class.moduleloader.php.

100 {
101 $startTime = microtime(true);
102 $maxWait = $timeout / 1000; // Convert to seconds
103
104 while (isset(self::$loading[$module])) {
105 if ((microtime(true) - $startTime) > $maxWait) {
106 Log::error('Timeout waiting for module: ' . $module);
107 return false;
108 }
109 usleep(10000); // Sleep 10ms before checking again
110 }
111
112 return true;
113 }
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 19 of file class.moduleloader.php.

◆ $maxWaitTime

$maxWaitTime = 5000
staticprivate

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

◆ $modules

$modules = array()
staticprivate

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

◆ APPS

const APPS = 'apps'

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

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

◆ BINS

const BINS = 'bins'

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

◆ CONFIG

const CONFIG = 'config'

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

◆ CORE

const CORE = 'core'

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

◆ HOMEPAGE

const HOMEPAGE = 'homepage'

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

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

◆ LANG

const LANG = 'lang'

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

◆ OPENSSL

const OPENSSL = 'openssl'

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

◆ REGISTRY

const REGISTRY = 'registry'

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

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

◆ TOOLS

const TOOLS = 'tools'

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

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

◆ WINBINDER

const WINBINDER = 'winbinder'

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


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