App
in package
implements
HttpServerInterface, ContainerInterface
Uses
Container
Application Factory
PHP Mini Framework
Tags
Interfaces, Classes, Traits and Enums
- HttpServerInterface
- PHP Mini Framework
- ContainerInterface
- PHP Mini Framework
Table of Contents
- $__instance : static
- $config : Config
- $env : string
- $isCli : bool
- $loader : LoaderInterface
- $logger : LoggerInterface
- $reporter : ErrorReportingInterface
- $router : RouterInterface
- $sessionManager : SessionBag
- $startTimeMs : int
- $stateless : bool
- $bindings : array<string|int, mixed>
- $completeHook : Closure|null
- $middlewares : array<string|int, MiddlewareInterface>|array<string|int, MiddlewareInterface>
- $startHook : Closure|null
- $status : int
- App current status
- $singletons : array<string|int, mixed>
- __construct() : mixed
- addBinding() : self
- Add interface binding. Binds interface to a specific class which implements it
- addMiddleware() : self
- Add middleware
- addSingleton() : self
- Add singleton
- afterComplete() : void
- Hook to run after processing request.
- beforeStart() : void
- Hook to run before processing request.
- delete() : RouteInterface
- Set HTTP DELETE routes
- get() : RouteInterface
- Set HTTP GET routes
- getBinding() : string|null
- Get interface binding
- getSingleton() : self
- Get singleton
- head() : RouteInterface
- Set HTTP HEAD routes
- make() : object
- Instantiate class with dependencies
- patch() : RouteInterface
- Set HTTP PATCH routes
- post() : RouteInterface
- Set HTTP POST routes
- put() : RouteInterface
- Set HTTP PUT routes
- run() : ResponseInterface
- Run application
- sendHttpResponse() : void
- Send HTTP JSON Response
- setErrorReporter() : self
- Set error reporter
- setLogger() : self
- Set Logger
- setRouter() : self
- Set router
- setSessionManager() : self
- Set Session Manager
- showMessage() : void
- Show Message
- triggerCompleteHook() : void
- Process on complete hook
- processMiddleware() : ResponseInterface
- Process middleware
- loadConfig() : self
- Load custom config file
- loadConfigs() : mixed
- Load custom configs
- setUpErrorHandlers() : mixed
- Set up error handlers
- triggerStartHook() : void
- Process on start request hook
Properties
$__instance
public
static static
$__instance
App instance
Tags
$config
public
Config
$config
Tags
$env
public
string
$env
= Env::LOCAL
Tags
$isCli
public
bool
$isCli
Tags
$loader
public
LoaderInterface
$loader
Tags
$logger
public
LoggerInterface
$logger
Tags
$reporter
public
ErrorReportingInterface
$reporter
Tags
$router
public
RouterInterface
$router
Tags
$sessionManager
public
SessionBag
$sessionManager
Tags
$startTimeMs
public
int
$startTimeMs
Request start time in milliseconds
Tags
$stateless
public
bool
$stateless
= false
Tags
$bindings
protected
array<string|int, mixed>
$bindings
= []
Tags
$completeHook
protected
Closure|null
$completeHook
= null
Tags
$middlewares
protected
array<string|int, MiddlewareInterface>|array<string|int, MiddlewareInterface>
$middlewares
= []
Tags
$startHook
protected
Closure|null
$startHook
= null
Tags
$status
App current status
protected
int
$status
= \Busarm\PhpMini\Enums\AppStatus::INITIALIZING
@see \Busarm\PhpMini\Enums\AppStatus
Tags
$singletons
private
array<string|int, mixed>
$singletons
= []
Tags
Methods
__construct()
public
__construct(Config $config[, string $env = Env::LOCAL ][, bool $stateless = false ]) : mixed
Parameters
- $config : Config
-
App configuration object
- $env : string = Env::LOCAL
-
App environment. @see Busarm\PhpMini\Enums\Env
- $stateless : bool = false
-
If app is running in stateless mode. E.g Using Swoole. Do not use static variables for user specific data when runing on stateless mode.
Stateless mode does not support adding:
- Application-wide Singletons
Tags
Return values
mixed —addBinding()
Add interface binding. Binds interface to a specific class which implements it
public
addBinding(string $interfaceName, string $className) : self
Parameters
- $interfaceName : string
- $className : string
Tags
Return values
self —addMiddleware()
Add middleware
public
addMiddleware(MiddlewareInterface|MiddlewareInterface $middleware) : self
Parameters
- $middleware : MiddlewareInterface|MiddlewareInterface
Tags
Return values
self —addSingleton()
Add singleton
public
addSingleton(string $className, object|null &$object) : self
Parameters
- $className : string
- $object : object|null
Tags
Return values
self —afterComplete()
Hook to run after processing request.
public
afterComplete(Closure $completeHook) : void
Use this to perform any custom post-request processing
This also registers a shutdown handler.
Parameters
- $completeHook : Closure
Tags
Return values
void —beforeStart()
Hook to run before processing request.
public
beforeStart(Closure $startHook) : void
Use this do perform any pre-validations such as maintainence mode checkings.
Parameters
- $startHook : Closure
Tags
Return values
void —delete()
Set HTTP DELETE routes
public
delete(string $path) : RouteInterface
Parameters
- $path : string
-
HTTP path. e.g /home. See
Router::MATCHER_REGXfor list of parameters matching keywords
Tags
Return values
RouteInterface —get()
Set HTTP GET routes
public
get(string $path) : RouteInterface
Parameters
- $path : string
-
HTTP path. e.g /home. See
Router::MATCHER_REGXfor list of parameters matching keywords
Tags
Return values
RouteInterface —getBinding()
Get interface binding
public
getBinding(string $interfaceName[, string $default = null ]) : string|null
Parameters
- $interfaceName : string
- $default : string = null
Tags
Return values
string|null —getSingleton()
Get singleton
public
getSingleton(string $className[, object $default = null ]) : self
Parameters
- $className : string
- $default : object = null
Tags
Return values
self —head()
Set HTTP HEAD routes
public
head(string $path) : RouteInterface
Parameters
- $path : string
-
HTTP path. e.g /home. See
Router::MATCHER_REGXfor list of parameters matching keywords
Tags
Return values
RouteInterface —make()
Instantiate class with dependencies
public
make(string $className[, array<string|int, mixed> $params = [] ][, RequestInterface|RouteInterface|null $request = null ]) : object
Parameters
- $className : string
- $params : array<string|int, mixed> = []
-
List of Custom params. (name => value) E.g [ 'request' => $request ]
- $request : RequestInterface|RouteInterface|null = null
-
HTTP request/route instance
Tags
Return values
object —patch()
Set HTTP PATCH routes
public
patch(string $path) : RouteInterface
Parameters
- $path : string
-
HTTP path. e.g /home. See
Router::MATCHER_REGXfor list of parameters matching keywords
Tags
Return values
RouteInterface —post()
Set HTTP POST routes
public
post(string $path) : RouteInterface
Parameters
- $path : string
-
HTTP path. e.g /home. See
Router::MATCHER_REGXfor list of parameters matching keywords
Tags
Return values
RouteInterface —put()
Set HTTP PUT routes
public
put(string $path) : RouteInterface
Parameters
- $path : string
-
HTTP path. e.g /home. See
Router::MATCHER_REGXfor list of parameters matching keywords
Tags
Return values
RouteInterface —run()
Run application
public
run([RequestInterface|RouteInterface|null $request = null ]) : ResponseInterface
Parameters
- $request : RequestInterface|RouteInterface|null = null
-
Custom request or route object
Tags
Return values
ResponseInterface —sendHttpResponse()
Send HTTP JSON Response
public
sendHttpResponse(int $status[, BaseDto|array<string|int, mixed>|object|string $data = null ][, array<string|int, mixed> $headers = [] ]) : void
Parameters
- $status : int
-
Status Code
- $data : BaseDto|array<string|int, mixed>|object|string = null
-
Data
- $headers : array<string|int, mixed> = []
-
Headers
Tags
Return values
void —setErrorReporter()
Set error reporter
public
setErrorReporter(ErrorReportingInterface $reporter) : self
Parameters
- $reporter : ErrorReportingInterface
Tags
Return values
self —setLogger()
Set Logger
public
setLogger(LoggerInterface $logger) : self
Parameters
- $logger : LoggerInterface
Tags
Return values
self —setRouter()
Set router
public
setRouter(RouterInterface $router) : self
Parameters
- $router : RouterInterface
Tags
Return values
self —setSessionManager()
Set Session Manager
public
setSessionManager(SessionBag $sessionManager) : self
Parameters
- $sessionManager : SessionBag
Tags
Return values
self —showMessage()
Show Message
public
showMessage(int $status[, string $message = null ][, string $errorCode = null ][, string $errorLine = null ][, string $errorFile = null ][, array<string|int, mixed> $errorTrace = [] ]) : void
Parameters
- $status : int
-
Status Code
- $message : string = null
-
Message
- $errorCode : string = null
- $errorLine : string = null
- $errorFile : string = null
- $errorTrace : array<string|int, mixed> = []
Tags
Return values
void —triggerCompleteHook()
Process on complete hook
public
triggerCompleteHook(RequestInterface|RouteInterface $request, ResponseInterface $response) : void
Parameters
- $request : RequestInterface|RouteInterface
- $response : ResponseInterface
Tags
Return values
void —processMiddleware()
Process middleware
protected
processMiddleware(RequestInterface|RouteInterface $request, ResponseInterface $response, array<string|int, MiddlewareInterface>|array<string|int, MiddlewareInterface> $middlewares) : ResponseInterface
Parameters
- $request : RequestInterface|RouteInterface
- $response : ResponseInterface
- $middlewares : array<string|int, MiddlewareInterface>|array<string|int, MiddlewareInterface>
Tags
Return values
ResponseInterface —loadConfig()
Load custom config file
private
loadConfig(string $config) : self
Parameters
- $config : string
-
File path relative to app path
Tags
Return values
self —loadConfigs()
Load custom configs
private
loadConfigs() : mixed
Tags
Return values
mixed —setUpErrorHandlers()
Set up error handlers
private
setUpErrorHandlers() : mixed
Tags
Return values
mixed —triggerStartHook()
Process on start request hook
private
triggerStartHook(RequestInterface|RouteInterface $request) : void
Parameters
- $request : RequestInterface|RouteInterface