App
in package
Class App.
Table of Contents
Properties
- $config : Config|null
- The Config instance.
- $debugCollector : AppCollector
- The App collector instance that is set when in debug mode.
- $defaultServerVars : array<string, mixed>
- Variables set in the $_SERVER super-global in command-line requests.
- $isCli : bool|null
- Tells if the request is by command line. Updating directly makes it possible to run tests simulating HTTP or CLI.
- $isRunning : bool
- Tells if the App is running.
- $services : array<string, array<string, object>>
- Array with keys with names of services and their values have arrays where the keys are the names of the instances and the values are the objects.
Methods
- __construct() : mixed
- Initialize the App.
- addDebugData() : void
- Add services data to the debug collector.
- antiCsrf() : AntiCSRF
- Get a antiCsrf service.
- autoloader() : Autoloader
- Get a autoloader service.
- cache() : Cache
- Get a cache service.
- config() : Config
- Get the Config instance.
- console() : Console
- Get a console service.
- database() : Database
- Get a database service.
- debugger() : Debugger
- Get a debugger service.
- exceptionHandler() : ExceptionHandler
- Get a exceptionHandler service.
- getService() : object|null
- Get a service.
- isCli() : bool
- Tell if it is a command-line request.
- isDebugging() : bool
- Tell if the App is in debug mode.
- language() : Language
- Get a language service.
- locator() : Locator
- Get a locator service.
- logger() : Logger
- Get a logger service.
- mailer() : Mailer
- Get a mailer service.
- migrator() : Migrator
- Get a migrator service.
- removeService() : void
- Remove services.
- request() : Request
- Get a request service.
- response() : Response
- Get a response service.
- router() : Router
- Get a router service.
- run() : void
- Detects if the request is via command-line and runs as a CLI request, otherwise runs as HTTP.
- runCli() : void
- Run the App on CLI requests.
- runHttp() : void
- Run the App on HTTP requests.
- session() : Session
- Get a session service.
- setIsCli() : void
- Set if it is a CLI request. Used for testing.
- setService() : T
- Set a service.
- validation() : Validation
- Get a validation service.
- view() : View
- Get a view service.
- addCommand() : bool
- Detects if the file has a command and adds it to the console.
- debugEnd() : void
- Ends the debugging of the App and prints the debugbar if there is no download file, if the request is not via AJAX and the Content-Type is text/html.
- debugStart() : void
- Start debugging the App.
- loadAutoloader() : void
- Make sure to load the autoloader service if its default config is set.
- loadConfigs() : array<string, array<string, mixed>>|null
- Load service configs catching exceptions.
- loadExceptionHandler() : void
- Make sure to load the exceptionHandler service if its default config is set.
- negotiateLanguage() : string
- Negotiates the language either via the command line or over HTTP.
- prepareToRun() : void
- Prepare the App to run via CLI or HTTP.
- requireRouterFiles() : void
- Load files that set the routes.
- setAntiCsrf() : AntiCSRF
- Set a antiCsrf service.
- setAutoloader() : Autoloader
- Set a autoloader service.
- setCache() : Cache
- Set a cache service.
- setConsole() : Console
- Set a console service.
- setDatabase() : Database
- Set a database service.
- setDebugger() : Debugger
- Set a debugger service.
- setExceptionHandler() : ExceptionHandler
- Set a exceptionHandler service.
- setLanguage() : Language
- Set a language service.
- setLocator() : Locator
- Set a locator service.
- setLogger() : Logger
- Set a logger service.
- setMailer() : Mailer
- Set a mailer service.
- setMigrator() : Migrator
- Set a migrator service.
- setRequest() : Request
- Set a request service.
- setResponse() : Response
- Set a response service.
- setRouter() : Router
- Set a router service.
- setServerVars() : void
- Overrides variables to be set in the $_SERVER super-global when the request is made via the command line.
- setSession() : Session
- Set a session service.
- setValidation() : Validation
- Set a validation service.
- setView() : View
- Set a view service.
Properties
$config
The Config instance.
protected
static Config|null
$config
$debugCollector
The App collector instance that is set when in debug mode.
protected
static AppCollector
$debugCollector
$defaultServerVars
Variables set in the $_SERVER super-global in command-line requests.
protected
static array<string, mixed>
$defaultServerVars
= ['REMOTE_ADDR' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'HTTP_HOST' => 'localhost']
$isCli
Tells if the request is by command line. Updating directly makes it possible to run tests simulating HTTP or CLI.
protected
static bool|null
$isCli
= null
$isRunning
Tells if the App is running.
protected
static bool
$isRunning
= false
$services
Array with keys with names of services and their values have arrays where the keys are the names of the instances and the values are the objects.
protected
static array<string, array<string, object>>
$services
= []
Methods
__construct()
Initialize the App.
public
__construct([Config|array<string, mixed>|string|null $config = null ][, bool $debug = false ]) : mixed
Parameters
- $config : Config|array<string, mixed>|string|null = null
-
The config
- $debug : bool = false
-
Set true to enable debug mode. False to disable.
addDebugData()
Add services data to the debug collector.
public
static addDebugData(string $service, string $instance, float $start, float $end) : void
Parameters
- $service : string
-
Service name
- $instance : string
-
Service instance name
- $start : float
-
Microtime right before setting up the service
- $end : float
-
Microtime right after setting up the service
antiCsrf()
Get a antiCsrf service.
public
static antiCsrf([string $instance = 'default' ]) : AntiCSRF
Parameters
- $instance : string = 'default'
-
The antiCsrf instance name
Return values
AntiCSRFautoloader()
Get a autoloader service.
public
static autoloader([string $instance = 'default' ]) : Autoloader
Parameters
- $instance : string = 'default'
-
The autoloader instance name
Return values
Autoloadercache()
Get a cache service.
public
static cache([string $instance = 'default' ]) : Cache
Parameters
- $instance : string = 'default'
-
The cache instance name
Return values
Cacheconfig()
Get the Config instance.
public
static config() : Config
Return values
Configconsole()
Get a console service.
public
static console([string $instance = 'default' ]) : Console
Parameters
- $instance : string = 'default'
-
The console instance name
Tags
Return values
Consoledatabase()
Get a database service.
public
static database([string $instance = 'default' ]) : Database
Parameters
- $instance : string = 'default'
-
The database instance name
Return values
Databasedebugger()
Get a debugger service.
public
static debugger([string $instance = 'default' ]) : Debugger
Parameters
- $instance : string = 'default'
-
The debugger instance name
Return values
DebuggerexceptionHandler()
Get a exceptionHandler service.
public
static exceptionHandler([string $instance = 'default' ]) : ExceptionHandler
Parameters
- $instance : string = 'default'
-
The exceptionHandler instance name
Return values
ExceptionHandlergetService()
Get a service.
public
static getService(string $name[, string $instance = 'default' ]) : object|null
Parameters
- $name : string
-
Service name
- $instance : string = 'default'
-
Service instance name
Return values
object|null —The service object or null
isCli()
Tell if it is a command-line request.
public
static isCli() : bool
Return values
boolisDebugging()
Tell if the App is in debug mode.
public
static isDebugging() : bool
Return values
boollanguage()
Get a language service.
public
static language([string $instance = 'default' ]) : Language
Parameters
- $instance : string = 'default'
-
The language instance name
Return values
Languagelocator()
Get a locator service.
public
static locator([string $instance = 'default' ]) : Locator
Parameters
- $instance : string = 'default'
-
The locator instance name
Return values
Locatorlogger()
Get a logger service.
public
static logger([string $instance = 'default' ]) : Logger
Parameters
- $instance : string = 'default'
-
The logger instance name
Return values
Loggermailer()
Get a mailer service.
public
static mailer([string $instance = 'default' ]) : Mailer
Parameters
- $instance : string = 'default'
-
The mailer instance name
Return values
Mailermigrator()
Get a migrator service.
public
static migrator([string $instance = 'default' ]) : Migrator
Parameters
- $instance : string = 'default'
-
The migrator instance name
Return values
MigratorremoveService()
Remove services.
public
static removeService(string $name[, string|null $instance = 'default' ]) : void
Parameters
- $name : string
-
Service name
- $instance : string|null = 'default'
-
Service instance name or null to remove all instances
request()
Get a request service.
public
static request([string $instance = 'default' ]) : Request
Parameters
- $instance : string = 'default'
-
The request instance name
Return values
Requestresponse()
Get a response service.
public
static response([string $instance = 'default' ]) : Response
Parameters
- $instance : string = 'default'
-
The response instance name
Return values
Responserouter()
Get a router service.
public
static router([string $instance = 'default' ]) : Router
Parameters
- $instance : string = 'default'
-
The router instance name
Return values
Routerrun()
Detects if the request is via command-line and runs as a CLI request, otherwise runs as HTTP.
public
run() : void
runCli()
Run the App on CLI requests.
public
runCli() : void
runHttp()
Run the App on HTTP requests.
public
runHttp() : void
session()
Get a session service.
public
static session([string $instance = 'default' ]) : Session
Parameters
- $instance : string = 'default'
-
The session instance name
Return values
SessionsetIsCli()
Set if it is a CLI request. Used for testing.
public
static setIsCli(bool $is) : void
Parameters
- $is : bool
setService()
Set a service.
public
static setService(string $name, T $service[, string $instance = 'default' ]) : T
Parameters
- $name : string
-
Service name
- $service : T
-
Service object
- $instance : string = 'default'
-
Service instance name
Tags
Return values
T —The service object
validation()
Get a validation service.
public
static validation([string $instance = 'default' ]) : Validation
Parameters
- $instance : string = 'default'
-
The validation instance name
Return values
Validationview()
Get a view service.
public
static view([string $instance = 'default' ]) : View
Parameters
- $instance : string = 'default'
-
The view instance name
Return values
ViewaddCommand()
Detects if the file has a command and adds it to the console.
protected
static addCommand(string $file, Console $console, Locator $locator) : bool
Parameters
- $file : string
-
The file to get the command class
- $console : Console
-
The console to add the class
- $locator : Locator
-
The locator to get the class name in the file
Tags
Return values
bool —True if the command was added. If not, it's false.
debugEnd()
Ends the debugging of the App and prints the debugbar if there is no download file, if the request is not via AJAX and the Content-Type is text/html.
protected
debugEnd() : void
debugStart()
Start debugging the App.
protected
debugStart() : void
loadAutoloader()
Make sure to load the autoloader service if its default config is set.
protected
loadAutoloader() : void
loadConfigs()
Load service configs catching exceptions.
protected
loadConfigs(string $name) : array<string, array<string, mixed>>|null
Parameters
- $name : string
-
The service name
Return values
array<string, array<string, mixed>>|null —The service configs or null
loadExceptionHandler()
Make sure to load the exceptionHandler service if its default config is set.
protected
loadExceptionHandler() : void
negotiateLanguage()
Negotiates the language either via the command line or over HTTP.
protected
static negotiateLanguage(Language $language[, string $requestInstance = 'default' ]) : string
Parameters
- $language : Language
-
The current Language instance
- $requestInstance : string = 'default'
-
The name of the Request instance to be used
Return values
string —The negotiated language
prepareToRun()
Prepare the App to run via CLI or HTTP.
protected
prepareToRun() : void
requireRouterFiles()
Load files that set the routes.
protected
static requireRouterFiles(array<string|int, string> $files, Router $router) : void
Parameters
- $files : array<string|int, string>
-
The path of the router files
- $router : Router
setAntiCsrf()
Set a antiCsrf service.
protected
static setAntiCsrf(string $instance) : AntiCSRF
Parameters
- $instance : string
-
The antiCsrf instance name
Return values
AntiCSRFsetAutoloader()
Set a autoloader service.
protected
static setAutoloader(string $instance) : Autoloader
Parameters
- $instance : string
-
The autoloader instance name
Return values
AutoloadersetCache()
Set a cache service.
protected
static setCache(string $instance) : Cache
Parameters
- $instance : string
-
The cache instance name
Return values
CachesetConsole()
Set a console service.
protected
static setConsole(string $instance) : Console
Parameters
- $instance : string
-
The console instance name
Tags
Return values
ConsolesetDatabase()
Set a database service.
protected
static setDatabase(string $instance[, DatabaseCollector|null $collector = null ]) : Database
Parameters
- $instance : string
-
The database instance name
- $collector : DatabaseCollector|null = null
Return values
DatabasesetDebugger()
Set a debugger service.
protected
static setDebugger(string $instance) : Debugger
Parameters
- $instance : string
-
The debugger instance name
Return values
DebuggersetExceptionHandler()
Set a exceptionHandler service.
protected
static setExceptionHandler(string $instance) : ExceptionHandler
Parameters
- $instance : string
-
The exceptionHandler instance name
Return values
ExceptionHandlersetLanguage()
Set a language service.
protected
static setLanguage(string $instance) : Language
Parameters
- $instance : string
-
The language instance name
Return values
LanguagesetLocator()
Set a locator service.
protected
static setLocator(string $instance) : Locator
Parameters
- $instance : string
-
The locator instance name
Return values
LocatorsetLogger()
Set a logger service.
protected
static setLogger(string $instance) : Logger
Parameters
- $instance : string
-
The logger instance name
Return values
LoggersetMailer()
Set a mailer service.
protected
static setMailer(string $instance) : Mailer
Parameters
- $instance : string
-
The mailer instance name
Return values
MailersetMigrator()
Set a migrator service.
protected
static setMigrator(string $instance) : Migrator
Parameters
- $instance : string
-
The migrator instance name
Return values
MigratorsetRequest()
Set a request service.
protected
static setRequest(string $instance) : Request
Parameters
- $instance : string
-
The request instance name
Return values
RequestsetResponse()
Set a response service.
protected
static setResponse(string $instance) : Response
Parameters
- $instance : string
-
The response instance name
Return values
ResponsesetRouter()
Set a router service.
protected
static setRouter(string $instance[, array<string|int, mixed>|null $config = null ]) : Router
Parameters
- $instance : string
-
The router instance name
- $config : array<string|int, mixed>|null = null
-
The router instance configs or null
Return values
RoutersetServerVars()
Overrides variables to be set in the $_SERVER super-global when the request is made via the command line.
protected
static setServerVars([array<string, mixed> $vars = [] ]) : void
Parameters
- $vars : array<string, mixed> = []
setSession()
Set a session service.
protected
static setSession(string $instance) : Session
Parameters
- $instance : string
-
The session instance name
Return values
SessionsetValidation()
Set a validation service.
protected
static setValidation(string $instance) : Validation
Parameters
- $instance : string
-
The validation instance name
Return values
ValidationsetView()
Set a view service.
protected
static setView(string $instance) : View
Parameters
- $instance : string
-
The view instance name