Aplus Framework Docs

App
in package

Class App.

Table of Contents

$config  : Config|null
The Config instance.
$debugCollector  : AppCollector
The App collector instance that is set when in debug mode.
$defaultServerVars  : array<string|int, 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|int, mixed>
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.
__construct()  : mixed
Initialize the App.
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.
addDebugData()  : void
Add services data to the debug collector.
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|int, 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|int, mixed> $services = []

Methods

__construct()

Initialize the App.

public __construct([array<string, mixed>|Config|string|null $config = null ][, bool $debug = false ]) : mixed
Parameters
$config : array<string, mixed>|Config|string|null = null

The config

$debug : bool = false

Set true to enable debug mode. False to disable.

Return values
mixed

antiCsrf()

Get a antiCsrf service.

public static antiCsrf([string $instance = 'default' ]) : AntiCSRF
Parameters
$instance : string = 'default'

The antiCsrf instance name

Return values
AntiCSRF

autoloader()

Get a autoloader service.

public static autoloader([string $instance = 'default' ]) : Autoloader
Parameters
$instance : string = 'default'

The autoloader instance name

Return values
Autoloader

cache()

Get a cache service.

public static cache([string $instance = 'default' ]) : Cache
Parameters
$instance : string = 'default'

The cache instance name

Return values
Cache

config()

Get the Config instance.

public static config() : Config
Return values
Config

console()

Get a console service.

public static console([string $instance = 'default' ]) : Console
Parameters
$instance : string = 'default'

The console instance name

Tags
throws
ReflectionException
Return values
Console

database()

Get a database service.

public static database([string $instance = 'default' ]) : Database
Parameters
$instance : string = 'default'

The database instance name

Return values
Database

debugger()

Get a debugger service.

public static debugger([string $instance = 'default' ]) : Debugger
Parameters
$instance : string = 'default'

The debugger instance name

Return values
Debugger

exceptionHandler()

Get a exceptionHandler service.

public static exceptionHandler([string $instance = 'default' ]) : ExceptionHandler
Parameters
$instance : string = 'default'

The exceptionHandler instance name

Return values
ExceptionHandler

getService()

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
bool

isDebugging()

Tell if the App is in debug mode.

public static isDebugging() : bool
Return values
bool

language()

Get a language service.

public static language([string $instance = 'default' ]) : Language
Parameters
$instance : string = 'default'

The language instance name

Return values
Language

locator()

Get a locator service.

public static locator([string $instance = 'default' ]) : Locator
Parameters
$instance : string = 'default'

The locator instance name

Return values
Locator

logger()

Get a logger service.

public static logger([string $instance = 'default' ]) : Logger
Parameters
$instance : string = 'default'

The logger instance name

Return values
Logger

mailer()

Get a mailer service.

public static mailer([string $instance = 'default' ]) : Mailer
Parameters
$instance : string = 'default'

The mailer instance name

Return values
Mailer

migrator()

Get a migrator service.

public static migrator([string $instance = 'default' ]) : Migrator
Parameters
$instance : string = 'default'

The migrator instance name

Return values
Migrator

removeService()

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

Return values
void

request()

Get a request service.

public static request([string $instance = 'default' ]) : Request
Parameters
$instance : string = 'default'

The request instance name

Return values
Request

response()

Get a response service.

public static response([string $instance = 'default' ]) : Response
Parameters
$instance : string = 'default'

The response instance name

Return values
Response

router()

Get a router service.

public static router([string $instance = 'default' ]) : Router
Parameters
$instance : string = 'default'

The router instance name

Return values
Router

run()

Detects if the request is via command-line and runs as a CLI request, otherwise runs as HTTP.

public run() : void
Return values
void

runCli()

Run the App on CLI requests.

public runCli() : void
Return values
void

runHttp()

Run the App on HTTP requests.

public runHttp() : void
Return values
void

session()

Get a session service.

public static session([string $instance = 'default' ]) : Session
Parameters
$instance : string = 'default'

The session instance name

Return values
Session

setIsCli()

Set if it is a CLI request. Used for testing.

public static setIsCli(bool $is) : void
Parameters
$is : bool
Return values
void

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
template

T of object

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
Validation

view()

Get a view service.

public static view([string $instance = 'default' ]) : View
Parameters
$instance : string = 'default'

The view instance name

Return values
View

addCommand()

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
throws
ReflectionException
Return values
bool

True if the command was added. If not, it's false.

addDebugData()

Add services data to the debug collector.

protected 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

Return values
void

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
Return values
void

debugStart()

Start debugging the App.

protected debugStart() : void
Return values
void

loadAutoloader()

Make sure to load the autoloader service if its default config is set.

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

setAntiCsrf()

Set a antiCsrf service.

protected static setAntiCsrf(string $instance) : AntiCSRF
Parameters
$instance : string

The antiCsrf instance name

Return values
AntiCSRF

setAutoloader()

Set a autoloader service.

protected static setAutoloader(string $instance) : Autoloader
Parameters
$instance : string

The autoloader instance name

Return values
Autoloader

setCache()

Set a cache service.

protected static setCache(string $instance) : Cache
Parameters
$instance : string

The cache instance name

Return values
Cache

setConsole()

Set a console service.

protected static setConsole(string $instance) : Console
Parameters
$instance : string

The console instance name

Tags
throws
ReflectionException
Return values
Console

setDatabase()

Set a database service.

protected static setDatabase(string $instance) : Database
Parameters
$instance : string

The database instance name

Return values
Database

setDebugger()

Set a debugger service.

protected static setDebugger(string $instance) : Debugger
Parameters
$instance : string

The debugger instance name

Return values
Debugger

setExceptionHandler()

Set a exceptionHandler service.

protected static setExceptionHandler(string $instance) : ExceptionHandler
Parameters
$instance : string

The exceptionHandler instance name

Return values
ExceptionHandler

setLanguage()

Set a language service.

protected static setLanguage(string $instance) : Language
Parameters
$instance : string

The language instance name

Return values
Language

setLocator()

Set a locator service.

protected static setLocator(string $instance) : Locator
Parameters
$instance : string

The locator instance name

Return values
Locator

setLogger()

Set a logger service.

protected static setLogger(string $instance) : Logger
Parameters
$instance : string

The logger instance name

Return values
Logger

setMailer()

Set a mailer service.

protected static setMailer(string $instance) : Mailer
Parameters
$instance : string

The mailer instance name

Return values
Mailer

setMigrator()

Set a migrator service.

protected static setMigrator(string $instance) : Migrator
Parameters
$instance : string

The migrator instance name

Return values
Migrator

setRequest()

Set a request service.

protected static setRequest(string $instance) : Request
Parameters
$instance : string

The request instance name

Return values
Request

setResponse()

Set a response service.

protected static setResponse(string $instance) : Response
Parameters
$instance : string

The response instance name

Return values
Response

setRouter()

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
Router

setServerVars()

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> = []
Return values
void

setSession()

Set a session service.

protected static setSession(string $instance) : Session
Parameters
$instance : string

The session instance name

Return values
Session

setValidation()

Set a validation service.

protected static setValidation(string $instance) : Validation
Parameters
$instance : string

The validation instance name

Return values
Validation

setView()

Set a view service.

protected static setView(string $instance) : View
Parameters
$instance : string

The view instance name

Return values
View

Search results