Application
extends Base
in package
implements
IMvcApplication
Class Application
Tags
Table of Contents
Interfaces
- IMvcApplication
- MVC Application Interface
Properties
- $_crashed : bool
- $_handleErrors : bool
- $_handleFatal : bool
- $_parameters : array<string|int, mixed>
- $_settings : SettingManager|null
- $_version : string
- $_basePath : string
- $_captureOutput : bool
- $_container : IContainer|null
- $_eventListenersPath : string
- $_output : string|null
- $_registry : Registry|null
- $_requests : array<string|int, mixed>
- $_router : Router
- $fs : IFileSystem
Methods
- __construct() : mixed
- Application constructor.
- addRoute() : RouteMap
- beautifyException() : string
- Format exception/error for display Base implementation outputs plain text (CLI-friendly) MVC Application overrides this for HTML output
- clearExpiredCache() : int
- Clear expired cache entries
- executeController() : mixed
- This method is called by the route lambdas and handles instantiating the required controller and calling the correct method.
- fatalHandler() : void
- Handler for fatal errors.
- getBasePath() : string
- getCaptureOutput() : bool
- getContainer() : IContainer
- Get the dependency injection container
- getCrashed() : bool
- getEventListenersPath() : string
- getOutput() : string
- getParameter() : mixed
- Gets a parameter by name.
- getParameters() : array<string|int, mixed>
- returns parameters passed to the run method.
- getRegistryObject() : mixed
- getRequest() : Request|null
- getRouter() : Router
- Get the application router instance
- getSetting() : mixed
- getSettingManager() : SettingManager|null
- getVersion() : string
- Application version number.
- globalExceptionHandler() : void
- Global exception handler for uncaught exceptions and errors Handles both Exception and Error (PHP 7+)
- handleException() : string
- hasContainer() : bool
- Check if container has been set
- initEvents() : void
- Loads event-listeners.yaml and maps all event listeners to their associated events.
- initLogger() : void
- Initializes the logger based on the parameters set in neuron.yaml.
- isCommandLine() : bool
- Returns true if the application is running in command line mode.
- phpErrorHandler() : bool
- Handler for PHP errors.
- run() : bool
- Call to run the application.
- setBasePath() : Base
- setCaptureOutput() : $this
- setContainer() : void
- Set the dependency injection container
- setEventListenersPath() : Base
- setHandleErrors() : Base
- setHandleFatal() : Base
- setRegistryObject() : mixed
- setSetting() : void
- setSettingSource() : $this
- willHandleErrors() : bool
- willHandleFatal() : bool
- configure404Route() : void
- configureRateLimit() : void
- Configure rate limiting if enabled in settings.
- executeInitializers() : void
- Executes all initializer classes located in app/Initializers.
- formatFatalError() : string
- Format fatal error for display Uses HTML for web, plain text for CLI
- initErrorHandlers() : void
- Sets up the php error and fatal handlers.
- initSettings() : void
- loadAttributeRoutes() : void
- Load routes from controller attributes
- loadRequests() : void
- loadRoutes() : void
- loadRoutingConfig() : void
- Load routing configuration from routing.yaml file.
- onCrash() : void
- Called by the fatal handler if invoked.
- onError() : bool
- Called for any unhandled exceptions.
- onFinish() : void
- Called immediately after onRun.
- onRun() : void
- Must be implemented by derived classes.
- onStart() : bool
- Called before onRun.
- registerAttributeRoute() : void
- Register a single route from an attribute definition
Properties
$_crashed
protected
bool
$_crashed
= false
$_handleErrors
protected
bool
$_handleErrors
= false
$_handleFatal
protected
bool
$_handleFatal
= false
$_parameters
protected
array<string|int, mixed>
$_parameters
$_settings
protected
SettingManager|null
$_settings
= null
$_version
protected
string
$_version
$_basePath
private
string
$_basePath
$_captureOutput
private
bool
$_captureOutput
= false
$_container
private
IContainer|null
$_container
= null
$_eventListenersPath
private
string
$_eventListenersPath
$_output
private
string|null
$_output
= ''
$_registry
private
Registry|null
$_registry
$_requests
private
array<string|int, mixed>
$_requests
= []
$_router
private
Router
$_router
$fs
private
IFileSystem
$fs
Methods
__construct()
Application constructor.
public
__construct([string $version = "1.0.0" ][, ISettingSource|null $source = null ][, IFileSystem|null $fs = null ]) : mixed
Parameters
- $version : string = "1.0.0"
- $source : ISettingSource|null = null
- $fs : IFileSystem|null = null
-
File system implementation (null = use real file system)
Tags
addRoute()
public
addRoute(string $method, string $route, string $controllerMethod[, string $request = '' ][, string|array<string|int, mixed> $filters = '' ][, string|null $name = null ]) : RouteMap
Parameters
- $method : string
- $route : string
- $controllerMethod : string
- $request : string = ''
- $filters : string|array<string|int, mixed> = ''
- $name : string|null = null
Tags
Return values
RouteMapbeautifyException()
Format exception/error for display Base implementation outputs plain text (CLI-friendly) MVC Application overrides this for HTML output
public
static beautifyException(Throwable $e) : string
Parameters
- $e : Throwable
Return values
stringclearExpiredCache()
Clear expired cache entries
public
clearExpiredCache() : int
Return values
int —Number of entries removed
executeController()
This method is called by the route lambdas and handles instantiating the required controller and calling the correct method.
public
executeController(array<string|int, mixed> $parameters[, string $requestName = '' ]) : mixed
Parameters
- $parameters : array<string|int, mixed>
- $requestName : string = ''
Tags
fatalHandler()
Handler for fatal errors.
public
fatalHandler() : void
Checks for actual fatal errors and formats them for display
getBasePath()
public
getBasePath() : string
Return values
stringgetCaptureOutput()
public
getCaptureOutput() : bool
Return values
boolgetContainer()
Get the dependency injection container
public
getContainer() : IContainer
Tags
Return values
IContainergetCrashed()
public
getCrashed() : bool
Return values
boolgetEventListenersPath()
public
getEventListenersPath() : string
Return values
stringgetOutput()
public
getOutput() : string
Return values
stringgetParameter()
Gets a parameter by name.
public
getParameter(string $name) : mixed
Parameters
- $name : string
getParameters()
returns parameters passed to the run method.
public
getParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>getRegistryObject()
public
getRegistryObject(string $name) : mixed
Parameters
- $name : string
getRequest()
public
getRequest(string $name) : Request|null
Parameters
- $name : string
Tags
Return values
Request|nullgetRouter()
Get the application router instance
public
getRouter() : Router
Return values
RoutergetSetting()
public
getSetting(string $section, string $name) : mixed
Parameters
- $section : string
- $name : string
getSettingManager()
public
getSettingManager() : SettingManager|null
Return values
SettingManager|nullgetVersion()
Application version number.
public
getVersion() : string
Return values
stringglobalExceptionHandler()
Global exception handler for uncaught exceptions and errors Handles both Exception and Error (PHP 7+)
public
globalExceptionHandler(Throwable $throwable) : void
Parameters
- $throwable : Throwable
handleException()
public
handleException(Throwable $e) : string
Parameters
- $e : Throwable
Return values
stringhasContainer()
Check if container has been set
public
hasContainer() : bool
Return values
boolinitEvents()
Loads event-listeners.yaml and maps all event listeners to their associated events.
public
initEvents() : void
initLogger()
Initializes the logger based on the parameters set in neuron.yaml.
public
initLogger() : void
destination format file level
Tags
isCommandLine()
Returns true if the application is running in command line mode.
public
isCommandLine() : bool
Return values
boolphpErrorHandler()
Handler for PHP errors.
public
phpErrorHandler(int $errorNo, string $message, string $file, int $line) : bool
Parameters
- $errorNo : int
- $message : string
- $file : string
- $line : int
Return values
boolrun()
Call to run the application.
public
run([array<string|int, mixed> $argv = [] ]) : bool
Parameters
- $argv : array<string|int, mixed> = []
Tags
Return values
boolsetBasePath()
public
setBasePath(string $basePath) : Base
Parameters
- $basePath : string
Return values
BasesetCaptureOutput()
public
setCaptureOutput(bool $captureOutput) : $this
Parameters
- $captureOutput : bool
Return values
$thissetContainer()
Set the dependency injection container
public
setContainer(IContainer $container) : void
Parameters
- $container : IContainer
setEventListenersPath()
public
setEventListenersPath(string $eventListenersPath) : Base
Parameters
- $eventListenersPath : string
Return values
BasesetHandleErrors()
public
setHandleErrors(bool $handleErrors) : Base
Parameters
- $handleErrors : bool
Return values
BasesetHandleFatal()
public
setHandleFatal(bool $handleFatal) : Base
Parameters
- $handleFatal : bool
Return values
BasesetRegistryObject()
public
setRegistryObject(string $name, mixed $object) : mixed
Parameters
- $name : string
- $object : mixed
setSetting()
public
setSetting(string $section, string $name, string $value) : void
Parameters
- $section : string
- $name : string
- $value : string
setSettingSource()
public
setSettingSource(ISettingSource $source) : $this
Parameters
- $source : ISettingSource
Return values
$thiswillHandleErrors()
public
willHandleErrors() : bool
Return values
boolwillHandleFatal()
public
willHandleFatal() : bool
Return values
boolconfigure404Route()
protected
configure404Route() : void
Tags
configureRateLimit()
Configure rate limiting if enabled in settings.
protected
configureRateLimit() : void
executeInitializers()
Executes all initializer classes located in app/Initializers.
protected
executeInitializers() : void
formatFatalError()
Format fatal error for display Uses HTML for web, plain text for CLI
protected
formatFatalError(string $type, string $message, string $file, int $line) : string
Parameters
- $type : string
- $message : string
- $file : string
- $line : int
Return values
stringinitErrorHandlers()
Sets up the php error and fatal handlers.
protected
initErrorHandlers() : void
initSettings()
protected
initSettings(ISettingSource|null $source) : void
Parameters
- $source : ISettingSource|null
loadAttributeRoutes()
Load routes from controller attributes
protected
loadAttributeRoutes() : void
Tags
loadRequests()
protected
loadRequests() : void
Tags
loadRoutes()
protected
loadRoutes() : void
Tags
loadRoutingConfig()
Load routing configuration from routing.yaml file.
protected
loadRoutingConfig() : void
This method loads URL rewrites and controller paths from the routing configuration file. If routing.yaml doesn't exist, it falls back to reading controller_paths from neuron.yaml for backward compatibility.
Tags
onCrash()
Called by the fatal handler if invoked.
protected
onCrash(array<string|int, mixed> $error) : void
Parameters
- $error : array<string|int, mixed>
onError()
Called for any unhandled exceptions.
protected
onError(string $message) : bool
Returning false skips executing onFinish.
Parameters
- $message : string
Return values
boolonFinish()
Called immediately after onRun.
protected
onFinish() : void
onRun()
Must be implemented by derived classes.
protected
onRun() : void
Tags
onStart()
Called before onRun.
protected
onStart() : bool
Tags
Return values
boolregisterAttributeRoute()
Register a single route from an attribute definition
protected
registerAttributeRoute(RouteDefinition $def) : void
Parameters
- $def : RouteDefinition