Application
extends AbstractApplication
in package
implements
ArrayAccess
Application class
Tags
Table of Contents
Interfaces
- ArrayAccess
Properties
- $config : mixed
- Application config
- $autoloader : ClassLoader|null
- Autoloader
- $events : Manager|null
- Event manager
- $fullName : string|null
- Full Name (Human-readable, e.g., "My Application")
- $middleware : Manager|null
- Middleware manager
- $modules : Manager|null
- Module manager
- $name : string|null
- Name (Slug, e.g. "my-app")
- $router : Router|null
- Application router
- $services : Locator|null
- Service locator
- $version : string|null
- Version
Methods
- __call() : static
- Magic method to register a route for a whitelisted custom HTTP method
- __construct() : mixed
- Constructor
- __get() : mixed
- Get a pre-designated value from the application object
- __isset() : bool
- Determine if a pre-designated value in the application object exists
- __set() : void
- Set a pre-designated value in the application object
- __unset() : void
- Unset a pre-designated value in the application object
- addConfigValue() : AbstractApplication
- Add new value to config
- addCustomMethod() : static
- Add a custom HTTP method to the whitelist
- addCustomMethods() : static
- Add multiple custom HTTP methods to the whitelist
- addMiddleware() : static
- Add a middleware handler
- addRoute() : static
- Add a route
- addRoutes() : static
- Add routes
- autoloader() : ClassLoader|null
- Get the autoloader object
- bootstrap() : static
- Bootstrap the application, creating the required objects if they haven't been created yet and registering with the autoloader, adding routes, services and events
- config() : mixed
- Access application config
- connect() : static
- Add a CONNECT route
- delete() : static
- Add a DELETE route
- deleteConfigValue() : AbstractApplication
- Replace existing value in config
- env() : mixed
- Get environment value
- environment() : string|null|bool
- Get application environment
- events() : Manager|null
- Get the event manager
- get() : static
- Add a GET route
- getFullName() : string
- Get full name
- getMiddleware() : mixed
- Get middleware
- getName() : string
- Get name
- getService() : mixed
- Get a service
- getVersion() : string
- Get version
- hasCustomMethod() : bool
- Determine if a custom HTTP method has been whitelisted
- hasFullName() : bool
- Determine if the full name is set
- hasName() : bool
- Determine if the name is set
- hasVersion() : bool
- Determine if version has been set
- head() : static
- Add a HEAD route
- init() : static
- Initialize the application
- isDev() : bool
- Check if application environment is dev
- isDown() : bool
- Check if application is in maintenance mode
- isLocal() : bool
- Check if application environment is local
- isProduction() : bool
- Check if application environment is production
- isRegistered() : bool
- Determine whether a module is registered with the application object
- isStaging() : bool
- Check if application environment is staging
- isTesting() : bool
- Check if application environment is testing
- isUp() : bool
- Check if application is in not maintenance mode
- load() : AbstractApplication
- Optional method that can be used to load custom operations/configurations for an application to run
- mergeApplication() : static
- Merge another application's services, middleware, events and config into this application
- mergeConfig() : AbstractApplication
- Merge new or altered config values with the existing config values
- mergeEvents() : static
- Merge another event manager's listeners into this application's event manager, combining listeners for shared event names instead of replacing them
- mergeMiddleware() : static
- Merge another middleware manager's items into this application's middleware manager
- mergeServices() : static
- Merge another service locator's items into this application's service locator
- middleware() : Manager|null
- Get the middleware manager
- module() : ModuleInterface|null
- Access a module object
- modules() : Manager|null
- Access all application module configs
- name() : string|null
- Get application name (alias method)
- off() : static
- Detach an event. Default hook-points are:
- offsetExists() : bool
- Determine if a pre-designated value in the application object exists
- offsetGet() : mixed
- Get a pre-designated value from the application object
- offsetSet() : void
- Set a pre-designated value in the application object
- offsetUnset() : void
- Unset a pre-designated value in the application object
- on() : static
- Attach an event. Default hook-points are:
- options() : static
- Add an OPTIONS route
- patch() : static
- Add a PATCH route
- post() : static
- Add a POST route
- put() : static
- Add a PUT route
- register() : static
- Register a module with the module manager object
- registerAutoloader() : static
- Register the autoloader object with the application
- registerConfig() : AbstractApplication
- Register a new configuration with the application
- registerEvents() : static
- Register a new event manager object with the application
- registerMiddleware() : static
- Register a new middleware manager object with the application
- registerModules() : static
- Register a new module manager object with the application
- registerRouter() : static
- Register a new router object with the application
- registerServices() : static
- Register a new service locator object with the application
- removeMiddleware() : static
- Remove middleware
- removeService() : static
- Remove a service
- router() : Router|null
- Access the application router
- run() : void
- Run the application
- services() : Locator|null
- Get the service locator
- setFullName() : static
- Set full name
- setName() : static
- Set name
- setService() : static
- Set a service
- setVersion() : static
- Set version
- trace() : static
- Add a TRACE route
- trigger() : static
- Trigger an event
- unregister() : static
- Unregister a module with the module manager object
- updateConfigValue() : AbstractApplication
- Update existing value in config
- url() : string|null
- Get application URL
- applyConfigEvents() : void
- If events are set in the app config, register them with the application
- applyConfigMetadata() : void
- Set the app name and version from config, if present
- applyConfigMiddleware() : void
- If middleware is defined in the app config, register them with the application
- applyConfigRoutes() : void
- If routes are set in the app config, register them with the application
- applyConfigServices() : void
- If services are set in the app config, register them with the application
- buildDispatch() : array<string|int, mixed>
- Build the dispatch closure and its params for the given dispatchable - used both as the deferred callable the middleware pipeline invokes once its handler chain completes, and by invokeDispatchable() to call the same logic immediately when there's no middleware to defer to
- hasPsr15Middleware() : bool
- Determine whether a PSR-15 middleware adapter is registered in the middleware stack
- httpRouter() : Router
- Get the active HTTP router, guarding that the application is routed for HTTP
- initializeDefaultManagers() : void
- Instantiate and register any manager objects not already set
- invokeDispatchable() : void
- Invoke the dispatchable directly, bypassing the middleware pipeline
- loadHelperFunctions() : void
- Load helper functions, unless disabled by config
- registerConfiguredAutoloaderPrefix() : void
- If the autoloader is set and the application config has a defined prefix and src, register with the autoloader
- renderMaintenanceResponse() : void
- Render a default maintenance-mode response for route targets that aren't a Dispatch\MaintenanceInterface (closures, callables) and so have no custom maintenance action of their own to run
- resolveMiddlewareRequest() : mixed
- Resolve the request object to pass into the middleware pipeline
Properties
$config
Application config
public
mixed
$config
$autoloader
Autoloader
protected
ClassLoader|null
$autoloader
= null
$events
Event manager
protected
Manager|null
$events
= null
$fullName
Full Name (Human-readable, e.g., "My Application")
protected
string|null
$fullName
= null
$middleware
Middleware manager
protected
Manager|null
$middleware
= null
$modules
Module manager
protected
Manager|null
$modules
= null
$name
Name (Slug, e.g. "my-app")
protected
string|null
$name
= null
$router
Application router
protected
Router|null
$router
= null
$services
Service locator
protected
Locator|null
$services
= null
$version
Version
protected
string|null
$version
= null
Methods
__call()
Magic method to register a route for a whitelisted custom HTTP method
public
__call(string $name, array<string|int, mixed> $arguments) : static
Parameters
- $name : string
- $arguments : array<string|int, mixed>
Tags
Return values
static__construct()
Constructor
public
__construct() : mixed
Instantiate an application object
Optional parameters are a service locator instance, a router instance, an event manager instance or a configuration object or array
__get()
Get a pre-designated value from the application object
public
__get(string $name) : mixed
Parameters
- $name : string
__isset()
Determine if a pre-designated value in the application object exists
public
__isset(string $name) : bool
Parameters
- $name : string
Return values
bool__set()
Set a pre-designated value in the application object
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
Tags
__unset()
Unset a pre-designated value in the application object
public
__unset(string $name) : void
Parameters
- $name : string
addConfigValue()
Add new value to config
public
addConfigValue(string $name, string $value) : AbstractApplication
Parameters
- $name : string
- $value : string
Return values
AbstractApplicationaddCustomMethod()
Add a custom HTTP method to the whitelist
public
addCustomMethod(string $method) : static
Parameters
- $method : string
Tags
Return values
staticaddCustomMethods()
Add multiple custom HTTP methods to the whitelist
public
addCustomMethods(array<string|int, mixed> $methods) : static
Parameters
- $methods : array<string|int, mixed>
Tags
Return values
staticaddMiddleware()
Add a middleware handler
public
addMiddleware(mixed $handler[, mixed $name = null ]) : static
Parameters
- $handler : mixed
- $name : mixed = null
Return values
staticaddRoute()
Add a route
public
addRoute(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Return values
staticaddRoutes()
Add routes
public
addRoutes(array<string|int, mixed> $routes) : static
Parameters
- $routes : array<string|int, mixed>
Return values
staticautoloader()
Get the autoloader object
public
autoloader() : ClassLoader|null
Return values
ClassLoader|nullbootstrap()
Bootstrap the application, creating the required objects if they haven't been created yet and registering with the autoloader, adding routes, services and events
public
bootstrap([ClassLoader|null $autoloader = null ]) : static
Parameters
- $autoloader : ClassLoader|null = null
Tags
Return values
staticconfig()
Access application config
public
config() : mixed
connect()
Add a CONNECT route
public
connect(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticdelete()
Add a DELETE route
public
delete(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticdeleteConfigValue()
Replace existing value in config
public
deleteConfigValue(string $name) : AbstractApplication
Parameters
- $name : string
Return values
AbstractApplicationenv()
Get environment value
public
env(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
- $default : mixed = null
environment()
Get application environment
public
environment([mixed $env = null ]) : string|null|bool
Parameters
- $env : mixed = null
Return values
string|null|boolevents()
Get the event manager
public
events() : Manager|null
Return values
Manager|nullget()
Add a GET route
public
get(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticgetFullName()
Get full name
public
getFullName() : string
Return values
stringgetMiddleware()
Get middleware
public
getMiddleware(mixed $name) : mixed
Parameters
- $name : mixed
getName()
Get name
public
getName() : string
Return values
stringgetService()
Get a service
public
getService(string $name) : mixed
Parameters
- $name : string
Tags
getVersion()
Get version
public
getVersion() : string
Return values
stringhasCustomMethod()
Determine if a custom HTTP method has been whitelisted
public
hasCustomMethod(string $method) : bool
Parameters
- $method : string
Tags
Return values
boolhasFullName()
Determine if the full name is set
public
hasFullName() : bool
Return values
boolhasName()
Determine if the name is set
public
hasName() : bool
Return values
boolhasVersion()
Determine if version has been set
public
hasVersion() : bool
Return values
boolhead()
Add a HEAD route
public
head(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticinit()
Initialize the application
public
init() : static
Return values
staticisDev()
Check if application environment is dev
public
isDev() : bool
Return values
boolisDown()
Check if application is in maintenance mode
public
isDown() : bool
Return values
boolisLocal()
Check if application environment is local
public
isLocal() : bool
Return values
boolisProduction()
Check if application environment is production
public
isProduction() : bool
Return values
boolisRegistered()
Determine whether a module is registered with the application object
public
isRegistered(string $name) : bool
Parameters
- $name : string
Return values
boolisStaging()
Check if application environment is staging
public
isStaging() : bool
Return values
boolisTesting()
Check if application environment is testing
public
isTesting() : bool
Return values
boolisUp()
Check if application is in not maintenance mode
public
isUp() : bool
Return values
boolload()
Optional method that can be used to load custom operations/configurations for an application to run
public
load() : AbstractApplication
Return values
AbstractApplicationmergeApplication()
Merge another application's services, middleware, events and config into this application
public
mergeApplication(Application $application[, bool $preserveConfig = false ][, array<string|int, mixed> $configExclude = [] ]) : static
Parameters
- $application : Application
- $preserveConfig : bool = false
- $configExclude : array<string|int, mixed> = []
Return values
staticmergeConfig()
Merge new or altered config values with the existing config values
public
mergeConfig(mixed $config[, bool $preserve = false ][, array<string|int, mixed> $exclude = [] ]) : AbstractApplication
Parameters
- $config : mixed
- $preserve : bool = false
- $exclude : array<string|int, mixed> = []
Tags
Return values
AbstractApplicationmergeEvents()
Merge another event manager's listeners into this application's event manager, combining listeners for shared event names instead of replacing them
public
mergeEvents(Manager $events) : static
Parameters
- $events : Manager
Return values
staticmergeMiddleware()
Merge another middleware manager's items into this application's middleware manager
public
mergeMiddleware(Manager $middleware) : static
Parameters
- $middleware : Manager
Return values
staticmergeServices()
Merge another service locator's items into this application's service locator
public
mergeServices(Locator $services) : static
Parameters
- $services : Locator
Return values
staticmiddleware()
Get the middleware manager
public
middleware() : Manager|null
Return values
Manager|nullmodule()
Access a module object
public
module(string $name) : ModuleInterface|null
Parameters
- $name : string
Return values
ModuleInterface|nullmodules()
Access all application module configs
public
modules() : Manager|null
Return values
Manager|nullname()
Get application name (alias method)
public
name() : string|null
Return values
string|nulloff()
Detach an event. Default hook-points are:
public
off(string $name, mixed $action) : static
app.init app.route.pre app.dispatch.pre app.dispatch.post app.error
Parameters
- $name : string
- $action : mixed
Return values
staticoffsetExists()
Determine if a pre-designated value in the application object exists
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
booloffsetGet()
Get a pre-designated value from the application object
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
offsetSet()
Set a pre-designated value in the application object
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Tags
offsetUnset()
Unset a pre-designated value in the application object
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
on()
Attach an event. Default hook-points are:
public
on(string $name, mixed $action[, int $priority = 0 ]) : static
app.init app.route.pre app.dispatch.pre app.dispatch.post app.error
Parameters
- $name : string
- $action : mixed
- $priority : int = 0
Return values
staticoptions()
Add an OPTIONS route
public
options(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticpatch()
Add a PATCH route
public
patch(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticpost()
Add a POST route
public
post(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticput()
Add a PUT route
public
put(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticregister()
Register a module with the module manager object
public
register(mixed $module[, string|null $name = null ]) : static
Parameters
- $module : mixed
- $name : string|null = null
Tags
Return values
staticregisterAutoloader()
Register the autoloader object with the application
public
registerAutoloader(ClassLoader $autoloader) : static
Parameters
- $autoloader : ClassLoader
Return values
staticregisterConfig()
Register a new configuration with the application
public
registerConfig(mixed $config) : AbstractApplication
Parameters
- $config : mixed
Tags
Return values
AbstractApplicationregisterEvents()
Register a new event manager object with the application
public
registerEvents(Manager $events) : static
Parameters
- $events : Manager
Return values
staticregisterMiddleware()
Register a new middleware manager object with the application
public
registerMiddleware(Manager $middleware) : static
Parameters
- $middleware : Manager
Return values
staticregisterModules()
Register a new module manager object with the application
public
registerModules(Manager $modules) : static
Parameters
- $modules : Manager
Return values
staticregisterRouter()
Register a new router object with the application
public
registerRouter(Router $router) : static
Parameters
- $router : Router
Return values
staticregisterServices()
Register a new service locator object with the application
public
registerServices(Locator $services) : static
Parameters
- $services : Locator
Return values
staticremoveMiddleware()
Remove middleware
public
removeMiddleware(mixed $name) : static
Parameters
- $name : mixed
Return values
staticremoveService()
Remove a service
public
removeService(string $name) : static
Parameters
- $name : string
Return values
staticrouter()
Access the application router
public
router() : Router|null
Return values
Router|nullrun()
Run the application
public
run([bool $exit = true ][, string|array<string|int, mixed>|null $forceRoute = null ]) : void
Parameters
- $exit : bool = true
- $forceRoute : string|array<string|int, mixed>|null = null
Tags
services()
Get the service locator
public
services() : Locator|null
Return values
Locator|nullsetFullName()
Set full name
public
setFullName(string $fullName) : static
Parameters
- $fullName : string
Return values
staticsetName()
Set name
public
setName(string $name) : static
Parameters
- $name : string
Return values
staticsetService()
Set a service
public
setService(string $name, mixed $service) : static
Parameters
- $name : string
- $service : mixed
Tags
Return values
staticsetVersion()
Set version
public
setVersion(string $version) : static
Parameters
- $version : string
Return values
statictrace()
Add a TRACE route
public
trace(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
statictrigger()
Trigger an event
public
trigger(string $name[, array<string|int, mixed> $args = [] ]) : static
Parameters
- $name : string
- $args : array<string|int, mixed> = []
Return values
staticunregister()
Unregister a module with the module manager object
public
unregister(string $name) : static
Parameters
- $name : string
Return values
staticupdateConfigValue()
Update existing value in config
public
updateConfigValue(string $name, string $value) : AbstractApplication
Parameters
- $name : string
- $value : string
Return values
AbstractApplicationurl()
Get application URL
public
url() : string|null
Return values
string|nullapplyConfigEvents()
If events are set in the app config, register them with the application
protected
applyConfigEvents() : void
applyConfigMetadata()
Set the app name and version from config, if present
protected
applyConfigMetadata() : void
applyConfigMiddleware()
If middleware is defined in the app config, register them with the application
protected
applyConfigMiddleware() : void
applyConfigRoutes()
If routes are set in the app config, register them with the application
protected
applyConfigRoutes() : void
applyConfigServices()
If services are set in the app config, register them with the application
protected
applyConfigServices() : void
buildDispatch()
Build the dispatch closure and its params for the given dispatchable - used both as the deferred callable the middleware pipeline invokes once its handler chain completes, and by invokeDispatchable() to call the same logic immediately when there's no middleware to defer to
protected
buildDispatch(mixed $dispatchable) : array<string|int, mixed>
Parameters
- $dispatchable : mixed
Return values
array<string|int, mixed>hasPsr15Middleware()
Determine whether a PSR-15 middleware adapter is registered in the middleware stack
protected
hasPsr15Middleware() : bool
Return values
boolhttpRouter()
Get the active HTTP router, guarding that the application is routed for HTTP
protected
httpRouter() : Router
Tags
Return values
RouterinitializeDefaultManagers()
Instantiate and register any manager objects not already set
protected
initializeDefaultManagers() : void
invokeDispatchable()
Invoke the dispatchable directly, bypassing the middleware pipeline
protected
invokeDispatchable(mixed $dispatchable) : void
Parameters
- $dispatchable : mixed
loadHelperFunctions()
Load helper functions, unless disabled by config
protected
loadHelperFunctions() : void
registerConfiguredAutoloaderPrefix()
If the autoloader is set and the application config has a defined prefix and src, register with the autoloader
protected
registerConfiguredAutoloaderPrefix() : void
renderMaintenanceResponse()
Render a default maintenance-mode response for route targets that aren't a Dispatch\MaintenanceInterface (closures, callables) and so have no custom maintenance action of their own to run
protected
renderMaintenanceResponse(bool $exit) : void
Parameters
- $exit : bool
resolveMiddlewareRequest()
Resolve the request object to pass into the middleware pipeline
protected
resolveMiddlewareRequest(mixed $dispatchable) : mixed
Parameters
- $dispatchable : mixed