Application
MMO\core · 1 symbol · generated 5 Oct 2026
Application
Application.php:62- Namespace
MMO\core- Extends
- aModule
- Implements
RequestHandlerInterface
Index
| OPENAPI_VERSION | ||
| PHASE_EXCEPTION | job is executed when an exception is not caught | |
| PHASE_RESPONSE | job is executed just before the response is sent to the server | |
| PHASE_RUN | job is executed just after the route has been dispatched | |
| PHASE_SHUTDOWN | job is executed just before the application shutdown (WARNING: not safe for long job) | |
| PHASE_START | job is executed just after the application has been waked up | |
| autoload | tells if application capture autoload | |
| errors | tells if application capture errors/exceptions | |
| exception | the last exception encountered | |
| inc | ||
| info | Application information (for API) | |
| jobs | ||
| logs | ||
| paths | Paths aliases | |
| phase | ||
| printer | current text dumper | |
| response | ||
| route | ||
| routes | {string: [\MMO\core\attributes\APIRoute]} the key is a group id (generally a classname) | |
| sortJobs | ||
| stream | the stream to write the logs in | |
| absoluteFilename($uri, $base) | Generate a valid absolute filename, resolving path. | |
| absoluteUrl($uri, $base) | Generate a valid absolute url, resolving path. | |
| addInfo($info) | Merge extra info (title/description/contact/...) into $info, used by api's OpenAPI document. | |
| addJob($trigger, $job, $when, $priority) | Register a job: $trigger is checked (and $job run if it returns true) during executeJobs, called once per phase this application goes through (PHASE_START/PHASE_RUN/PHASE_RESPONSE/ | |
| addJobs($jobs) | ||
| addLog($log) | Write log in the log stream (if any) or add it to the pool. | |
| addRoute($groupId, $route) | Add one more route to $groupId (creating the group if needed), on top of whatever connectRoutes already extracted. | |
| api() | ||
| captureAutoload($capture) | Set/unset php autoload hook | |
| captureErrors($capture) | Set/unset php error hook | |
| classUrl($class, $extension, $resolve) | Convert a classname/namespace into an uri with an path | |
| clearLogs($disableLogs) | ||
| clearRoutes() | Remove every registered route. | |
| connectRoutes($class, $config) | Connect route of a class or a function | |
| createErrorResponse($e) | Called by the route when an exception occurs, or by the php exception handler. | |
| DefaultConfig() static | ||
| dump($values) | Dump $values using whichever printer matches the current response's content type (falling back to $printer before any response exists). | |
| executeJobs($when) | Run every job (addJob) whose trigger currently returns true and whose $when includes $when; a job throwing is logged, not propagated. | |
| extractRoutes($class, $config) | Extract api routes from a function/class attributes | |
| findRoute($groupId, $operation) | ||
| getDescription() | ||
| getIcon() | ||
| getIncludes() | ||
| getJobs($when, $executeTrigger) | ||
| getJobTrigger($job) | ||
| getLogs($flush) | Get and flush the logs in the pool. | |
| getPath($path) | ||
| getPaths($resolve) | Get all alias for paths | |
| getPhase() | ||
| getRequest() | ||
| getResponse() | ||
| getRoute() | ||
| getRoutes($groupId) | ||
| getTitle() | ||
| getTriggerJob($trigger) | ||
| getVersion() | ||
| getWorker($id, $regex) | ||
| getWorkerFile() | ||
| getWorkers() | ||
| handle($request) | ||
| hasRoutes($groupId) | ||
| isCapturingAutoload() | ||
| isCapturingErrors() | ||
| onAutoload($event) | ||
| phpAutoload($class) | Magic php autoload handler Use directly spl_autoload_register | |
| phpError($no, $str, $file, $line, $context) | Magic php error handler Maps a raw PHP error (set_error_handler) to a log level and message, ignoring the @-suppression operator by design -- so an error a caller tried to silence via @ is… | |
| phpException($e) | Magic php exception handler Called for a truly uncaught exception (set_exception_handler) -- logs it, dispatches it if it's an | |
| phpShutdown() | Shutdown function call by register_shutdown_function WARNING: DO NOT call directly. | |
| registerWorker($cmd, $pid) | Record a background worker (runWorker) in the registry file (getWorkerFile), appending to it. | |
| removeJob($fn) | Remove a job from a trigger or a job | |
| removeRoutes($groupId) | ||
| resolvePath($uri, $maxRecursivity) | Resolve path recursively. | |
| routeAPI($route) | API endpoint serving api's OpenAPI document; stops further middleware so nothing else can alter it. | |
| run($request) | Run and exit the application | |
| runInteractive($request) | Run the application, executing middlewares and returns a Response or an exception | |
| runWorker($cmd, $sleep) | Start $cmd as a detached background process and register it (registerWorker). | |
| sendResponse($response) | Call this function to send a response | |
| setDescription($value) | ||
| setIcon($icon) | ||
| setIncludes($pkgs) | Include packages after the project and the application has been instantiated | |
| setPath($path, $value) | Set a path for an uri part A path xxx replace any uri parts named {xxx} | |
| setPaths($paths, $isWindows) | Set path for given paths. | |
| setPhase($phase) | Advance to $phase and run every job registered for it (executeJobs). | |
| setRoutes($routes) | ||
| setStream($stream) | Set the stream to write the logs in | |
| setTitle($value) | ||
| __construct($config) | ||
| __wakeup() | Registers this class's own routes (routeAPI) and advances to PHASE_START. |
Constants6
OPENAPI_VERSION
PHASE_EXCEPTION
job is executed when an exception is not caught
PHASE_RESPONSE
job is executed just before the response is sent to the server
PHASE_RUN
job is executed just after the route has been dispatched
PHASE_SHUTDOWN
job is executed just before the application shutdown (WARNING: not safe for long job)
PHASE_START
job is executed just after the application has been waked up
Properties15
autoload
tells if application capture autoload
- Type
- bool
errors
tells if application capture errors/exceptions
- Type
- bool
exception
the last exception encountered
inc
- Type
- array
info
Application information (for API)
- Type
- array
jobs
- Type
- array
logs
- Type
- array
paths
Paths aliases
- Type
- array
phase
- Type
- int
printer
current text dumper
- Type
- TextPrinter
response
route
routes
{string: [\MMO\core\attributes\APIRoute]} the key is a group id (generally a classname)
- Type
- array
sortJobs
- Type
- bool
stream
the stream to write the logs in
- Type
- null |
StreamInterface
Methods68
absoluteFilename($uri, $base)
Application.php:641Generate a valid absolute filename, resolving path.
absoluteUrl($uri, $base)
Application.php:670Generate a valid absolute url, resolving path.
addInfo($info)
Application.php:999Merge extra info (title/description/contact/...) into $info, used by api's OpenAPI document.
addJob($trigger, $job, $when, $priority)
Application.php:422Register a job: $trigger is checked (and $job run if it returns true) during executeJobs, called once per phase this application goes through (PHASE_START/PHASE_RUN/PHASE_RESPONSE/
- See
PHASE_SHUTDOWN/PHASE_EXCEPTION). If $when only names phase(s) already passed, $trigger is checked immediately instead (sinceexecuteJobswill never reach them again).
addJobs($jobs)
Application.php:408addLog($log)
Application.php:367Write log in the log stream (if any) or add it to the pool.
addRoute($groupId, $route)
Application.php:742Add one more route to $groupId (creating the group if needed), on top of whatever connectRoutes already extracted. @return APIRoute $route, for chaining.
api()
Application.php:1033| returns | array | an OpenAPI 3.0 document describing every registered route (APIRoute::api). |
captureAutoload($capture)
Application.php:1236Set/unset php autoload hook
captureErrors($capture)
Application.php:1195Set/unset php error hook
classUrl($class, $extension, $resolve)
Application.php:620Convert a classname/namespace into an uri with an path
clearLogs($disableLogs)
Application.php:400clearRoutes()
Application.php:711Remove every registered route.
| returns | self |
connectRoutes($class, $config)
Application.php:807Connect route of a class or a function
createErrorResponse($e)
Application.php:888Called by the route when an exception occurs, or by the php exception handler.
DefaultConfig()
staticApplication.php:128| returns | array |
dump($values)
Application.php:218Dump $values using whichever printer matches the current response's content type (falling back to $printer before any response exists).
| ...$values | mixed | |
| returns |
executeJobs($when)
Application.php:504Run every job (addJob) whose trigger currently returns true and whose $when includes $when; a job throwing is logged, not propagated.
extractRoutes($class, $config)
Application.php:769Extract api routes from a function/class attributes
findRoute($groupId, $operation)
Application.php:732getDescription()
Application.php:1003| returns | string |
getIcon()
Application.php:1019getIncludes()
Application.php:240| returns | array | the packages passed to the last setIncludes call. |
getJobs($when, $executeTrigger)
Application.php:485| $when = -1 | object | int | a PHASE_* bitmask, or an object instance to find jobs bound to (matches a [$instance, 'method']-style job callable whose object is === $when). |
| $executeTrigger = false | bool | if true, only include jobs whose trigger currently returns true (and actually call each one). |
| returns | array | every matching job callable. |
getJobTrigger($job)
Application.php:446getLogs($flush)
Application.php:393Get and flush the logs in the pool.
getPath($path)
Application.php:555getPaths($resolve)
Application.php:533Get all alias for paths
getPhase()
Application.php:517| returns | int | the current PHASE_* constant. |
getRequest()
Application.php:698| returns | ServerRequestInterface | the current route's request, or (before handling one) a freshly-built one from the real environment (CLI argv or the real HTTP request). |
getResponse()
Application.php:936| returns | null | iResponse | the response sendResponse actually sent, or null before one has been sent. |
getRoute()
Application.php:693getRoutes($groupId)
Application.php:706getTitle()
Application.php:1011| returns | string |
getTriggerJob($trigger)
Application.php:457getVersion()
Application.php:1028| returns | null | string | the project's own version (PackageManager::getProjectManifest), or null if no project manifest is set. |
getWorker($id, $regex)
Application.php:323| $id | string | a pid or exact command to match, or (with $regex) a regex to match the command against. |
| $regex = false | bool | |
| returns | null | array | the matching worker (getWorkers' shape), or null. |
getWorkerFile()
Application.php:247| returns | string | the registry file tracking background workers (registerWorker/getWorkers). |
getWorkers()
Application.php:285| returns | array | [['date' => ..., 'pid' => ..., 'cmd' => ..., 'main' => the registering process's own pid, 'run' => bool whether it's still running], ...] -- every registered worker; also prunes no-longer-running ones from the registry file as a side effect (deleting the file entirely once none are left). |
handle($request)
Application.php:825- See
RequestHandlerInterface::handle-- match $request against every registered route (connectRoutes), adding a middleware for each match (Route::addMiddleware), thenRoute::dispatchandRoute::handleit. An uncaught exception from the route becomes an error response instead (createErrorResponse), via the route's own error handler if it set one.
| $request | ServerRequestInterface | |
| returns | iResponse |
hasRoutes($groupId)
Application.php:758isCapturingAutoload()
Application.php:1227| returns | bool | whether classes are currently routed through onAutoload (phpAutoload). |
isCapturingErrors()
Application.php:1186| returns | bool | whether PHP errors/exceptions are currently routed through phpError/phpException. |
onAutoload($event)
Application.php:206phpAutoload($class)
Application.php:1142Magic php autoload handler Use directly spl_autoload_register
phpError($no, $str, $file, $line, $context)
Application.php:1070Magic php error handler Maps a raw PHP error (set_error_handler) to a log level and message, ignoring the @-suppression operator by design -- so an error a caller tried to silence via @ is still logged/recorded, just not displayed.
phpException($e)
Application.php:1121Magic php exception handler Called for a truly uncaught exception (set_exception_handler) -- logs it, dispatches it if it's an
- See
iException, and (if nothing has already sent a response) sends an error response for it (createErrorResponse).
phpShutdown()
Application.php:1151Shutdown function call by register_shutdown_function WARNING: DO NOT call directly. It is called automatically by the shutdown process.
| returns | void |
registerWorker($cmd, $pid)
Application.php:274Record a background worker (runWorker) in the registry file (getWorkerFile), appending to it.
removeJob($fn)
Application.php:469Remove a job from a trigger or a job
removeRoutes($groupId)
Application.php:749resolvePath($uri, $maxRecursivity)
Application.php:599Resolve path recursively.
routeAPI($route)
Application.php:1054API endpoint serving api's OpenAPI document; stops further middleware so nothing else can alter it.
run($request)
Application.php:928Run and exit the application
runInteractive($request)
Application.php:918Run the application, executing middlewares and returns a Response or an exception
runWorker($cmd, $sleep)
Application.php:259Start $cmd as a detached background process and register it (registerWorker).
| $cmd | string | |
| $sleep = 1 | int | seconds to wait before checking the process actually started. |
| returns | string | the new process's PID. |
| throws | if the process doesn't appear to be running after $sleep seconds (already running under this exact command, per getWorker, is reported specifically; anything else is a generic failure). |
sendResponse($response)
Application.php:947Call this function to send a response
| $response | iResponse | |
| returns | bool | false if the response's own dispatch stopped propagation (nothing was sent), or if sending itself failed (logged as critical, not thrown). |
| throws | if a response has already been sent (getResponse). |
setDescription($value)
Application.php:1007setIcon($icon)
Application.php:1023setIncludes($pkgs)
Application.php:234Include packages after the project and the application has been instantiated
setPath($path, $value)
Application.php:565Set a path for an uri part A path xxx replace any uri parts named {xxx}
setPaths($paths, $isWindows)
Application.php:585Set path for given paths.
setPhase($phase)
Application.php:522Advance to $phase and run every job registered for it (executeJobs).
setRoutes($routes)
Application.php:717| $routes | array | group-id => config (or a plain list of group-ids with no config), each passed to connectRoutes. |
| returns | void |
setStream($stream)
Application.php:339Set the stream to write the logs in
setTitle($value)
Application.php:1015__construct($config)
Application.php:181| $config | array |
__wakeup()
Application.php:200Registers this class's own routes (routeAPI) and advances to PHASE_START.
| returns | void |
Inherited members (46)
| Constants | Declared by | Description | |
|---|---|---|---|
ALERT | iLogLevel | Alert: Action must be taken immediately. | |
ALL | iLogLevel | Mask for all | |
ALL_PLUS | iLogLevel | debug everything | |
BACKTRACE | iLogLevel | ||
CRITICAL | iLogLevel | Critical: Critical conditions. | |
DEBUG | iLogLevel | Debug: Detailed debug information. | |
DEEP | iLogLevel | debug everything with arguments | |
EMERGENCY | iLogLevel | Emergency: System is unusable. | |
ERROR | iLogLevel | Error: Runtime errors that do not require immediate action but should typically be logged and monitored. | |
ERROR_PLUS | iLogLevel | Mask for all error | |
FATAL | iLogLevel | Mask for all fatal error | |
INFO | iLogLevel | Info: Interesting events. | |
INFO_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
MEMORY | iLogLevel | include backtrace object | |
NOTICE | iLogLevel | Notice: Normal but significant events. | |
NOTICE_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
TRACE | iLogLevel | include backtrace as origins | |
WARNING | iLogLevel | Warning: Exceptional occurrences that are not errors. | |
WARNING_PLUS | iLogLevel | Mask for all errors and warnings |
| Properties | Declared by | Description | |
|---|---|---|---|
verbosity | aModule |
| Methods | Declared by | Description | |
|---|---|---|---|
alert($message, $context) | aModule | Action must be taken immediately. | |
backtraces($message, $context) | aModule | Force-log a message at INFO level together with a full stack trace/memory snapshot (iLogLevel::BACKTRACE), bypassing the verbosity mask entirely (any non-zero verbosity is enough to trigger it). | |
Configure($config) | aModule | Merge $config into this module's configuration in the shared Configuration. | |
critical($message, $context) | aModule | Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask. | |
debug($message, $context) | aModule | Detailed debug information. | |
debugName() | aModule | Human-readable identifier used as the default {origin} in this instance's log messages. | |
emergency($message, $context) | aModule | System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask. | |
error($message, $context) | aModule | Runtime errors that do not require immediate action but should typically be logged and monitored. | |
getVerbosity() | aModule | ||
info($message, $context) | aModule | Interesting events. No-op if INFO is currently filtered out by the verbosity mask. | |
Instantiate($config) | aModule | (Re)create the shared instance immediately, configured with $config merged into the class's existing config. | |
IsShared() | aModule | ||
log($level, $message, $context) | aModule | Logs with an arbitrary level. | |
notice($message, $context) | aModule | Normal but significant events. | |
offsetExists($key) | aModule | \ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access. | |
offsetGet($key) | aModule | \ArrayAccess::offsetGet -- reads a property directly, unless it has a #[Serialize(serialize: 'methodName')] attribute, in which case that zero-argument method is called instead (e.g. | |
offsetSet($key, $value) | aModule | \ArrayAccess::offsetSet -- sets a property directly, unless it has a #[Serialize(unserialize: 'methodName')] attribute, in which case that method is called with $value instead (e.g. | |
offsetUnset($key) | aModule | \ArrayAccess::offsetUnset -- equivalent to $module[$key] = null. | |
serialize($path, $serializer) | aModule | \MMO\core\interfaces\iSerializable::serialize -- exports every property (via | |
setVerbosity($verb) | aModule | Set the current verbosity mask, replacing whatever it was before. | |
Shared() | aModule | Get the shared instance, creating (and configuring) it on first call. | |
testVerbosity($level) | aModule | Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask. | |
traitUnshare($serialize) | aModule | Remove the shared instance, so the next Shared() call creates a fresh one. | |
unserialize($data, $path, $instances) | aModule | \MMO\core\interfaces\iSerializable::unserialize -- merges $data onto DefaultConfig, runs it through the (possibly overridden) constructor, then applies each resulting value to its property (via | |
Unshare($serialize) | aModule | Like tSingleton::Unshare, but also disconnects this module's instance from every event it was listening to (via Event::DisconnectListeners) before dropping it. | |
warning($message, $context) | aModule | Exceptional occurrences that are not errors. |