PHP Mini Documentation

App
in package
implements HttpServerInterface

Application Factory

PHP Mini Framework

Tags
copyright

busarm.com

license

https://github.com/Busarm/php-mini/blob/master/LICENSE (MIT License)

Interfaces, Classes, Traits and Enums

HttpServerInterface
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
$bindings  : array<string|int, mixed>
$completeHook  : Closure|null
$middlewares  : array<string|int, MiddlewareInterface>
$resolvers  : array<string|int, mixed>
$singletons  : array<string|int, mixed>
$startHook  : Closure|null
__construct()  : mixed
addBinding()  : self
Add interface binding. Binds interface to a specific class which implements it
addLogger()  : self
Add Logger. Replaces existing
addMiddleware()  : self
Add middleware
addResolver()  : self
Add resolver
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
getResolver()  : Closure|null
Get resolver
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()  : ResponseInterface|null
Send HTTP JSON Response
setErrorReporter()  : self
Set error reporter
setRouter()  : self
Set router
setSessionManager()  : self
Set Session Manager
showMessage()  : void
Show Message
triggerCompleteHook()  : void
Process on complete hook
processMiddleware()  : false|mixed
Process middleware
loadConfig()  : self
Load custom config file
loadConfigs()  : mixed
Load custom configs
setUpErrorHandlers()  : mixed
Set up error handlers
triggerStartHook()  : void
Process on start hook

Properties

$__instance

public static static $__instance

App instance

Tags

$env

public string $env = Env::LOCAL
Tags

$isCli

public bool $isCli
Tags

$logger

public LoggerInterface $logger
Tags

$startTimeMs

public int $startTimeMs

Request start time in milliseconds

Tags

$bindings

protected array<string|int, mixed> $bindings = []
Tags

$completeHook

protected Closure|null $completeHook = null
Tags

$resolvers

protected array<string|int, mixed> $resolvers = []
Tags

$singletons

protected array<string|int, mixed> $singletons = []
Tags

$startHook

protected Closure|null $startHook = null
Tags

Methods

__construct()

public __construct(Config $config[, string $env = Env::LOCAL ]) : mixed
Parameters
$config : Config

App configuration object

$env : string = Env::LOCAL

App environment. @see Busarm\PhpMini\Enums\Env

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

addLogger()

Add Logger. Replaces existing

public addLogger(LoggerInterface $logger) : self
Parameters
$logger : LoggerInterface
Tags
Return values
self

addResolver()

Add resolver

public addResolver(string $name, mixed &$result) : self
Parameters
$name : string

Class name, Interface name or Unique name of resolver

$result : mixed

Result of the resolution. e.g Class object

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

This registers a shutdown handler.

Parameters
$completeHook : Closure
Tags
see
register_shutdown_function
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_REGX for 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_REGX for 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

getResolver()

Get resolver

public getResolver(string $name) : Closure|null
Parameters
$name : string
Tags
Return values
Closure|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_REGX for list of parameters matching keywords

Tags
Return values
RouteInterface

make()

Instantiate class with dependencies

public make(string $className[, bool $cache = false ][, array<string|int, mixed> $params = [] ]) : object
Parameters
$className : string
$cache : bool = false

Save as singleton to be reused. Default: false

$params : array<string|int, mixed> = []

List of Custom params. (name => value) E.g [ 'request' => $request ]

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_REGX for 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_REGX for 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_REGX for list of parameters matching keywords

Tags
Return values
RouteInterface

sendHttpResponse()

Send HTTP JSON Response

public sendHttpResponse(int $status[, BaseDto|array<string|int, mixed>|object|string $data = null ][, array<string|int, mixed> $headers = [] ]) : ResponseInterface|null
Parameters
$status : int

Status Code

$data : BaseDto|array<string|int, mixed>|object|string = null

Data

$headers : array<string|int, mixed> = []

Headers

Tags
Return values
ResponseInterface|null

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() : void
Tags
Return values
void

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 hook

private triggerStartHook() : void
Tags
Return values
void

        

Search results