Pionia Core

PioniaApplication extends Application
in package
implements ApplicationContract, LoggerAwareInterface Uses ApplicationLifecycleHooks, AppHelpersTrait, Microable, PathsTrait, AppDatabaseHelper, BuiltInServices, Cacheable, Containable

Table of Contents

Interfaces

ApplicationContract
LoggerAwareInterface

Properties

$appName  : string
Application name
$appVersion  : string
Framework version
$cachePrefix  : string
The cache prefix to use for caching.
$cacheTtl  : int
The cache ttl to use for caching.
$context  : ContainerInterface|Container|null
Application container context
$dispatcher  : PioniaEventDispatcher|null
Event dispatcher
$env  : Arrayable|null
Environment variables
$logger  : LoggerInterface|null
Logger instance
$applicationType  : PioniaApplicationType|null
Application type
$booted  : bool
$bootedCallbacks  : array<string|int, mixed>
The booted callbacks
$bootingCallbacks  : array<string|int, mixed>
The booting callbacks, callbacks to call before the app runs
$cacheAdaptor  : PioniaCacheAdaptor|null
$envResolver  : EnvResolver|null
Environment resolver
$macros  : array<string|int, mixed>
$terminatedCallbacks  : array<string|int, mixed>
The terminated callbacks, run after terminating the application
$terminatingCallbacks  : array<string|int, mixed>
The terminating callbacks, run before terminating the application
$APP_NAME  : string
$cacheInstance  : PioniaCache|null
The cache instance to use for caching.
$version  : string

Methods

__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__construct()  : mixed
PioniaApplication constructor.
addAlias()  : static
Adds an alias to the context list of aliases
addMiddleware()  : $this
Add a single middleware to the chain
addQueryToPool()  : static
alias()  : mixed
Get any alias from the context
allowedOrigins()  : $this
If set, these shall be the only addresses that can access the application
appName()  : string
Our application name
appRoot()  : string
The root folder of the application.
blockedOrigins()  : $this
If set, these origins shall be prevented from accessing the application
bootConsole()  : int
booted()  : static
Register callbacks to be run after the application is booted This method can be called multiple times to add more hooks
booting()  : $this
Register hooks to mutate the application booting cycle.
cache()  : bool|mixed
Caches the value if the value is not null.
ClearByKeys()  : bool
Clear the cache.
contextArrAdd()  : void
contextHas()  : bool
Check if a value exists in the container
contextMake()  : mixed
Make an instance of a class from the container. This will throw an exception if the class is not found
contextMakeSilently()  : mixed
Create an instance of a class without throwing an exception when it fails
ddInfo()  : Arrayable
Return everything about database connections discovered
defaultOrFirst()  : mixed
Get a database connection from the pool of connections we have
deleteCache()  : bool
Delete the cache for the key.
dispatch()  : void
Dispatches an event from anywhere in the application
environment()  : string
envPath()  : string
flushMacros()  : void
Remove all the macros we had registered
formatCommandString()  : string
Format the given command as a fully-qualified executable command.
getAppName()  : mixed
getCache()  : mixed
getCacheInstance()  : PioniaCache|null
getDirFor()  : string|null
Get the directory for a given alias
getDiscoveredConnections()  : Arrayable
Get the discovered database connections that are available in our environment
getEnv()  : PioniaApplicationType
Get all the environment variables or the value of a single key Will check in the $_ENV, $_SERVER, container, and in the local env array for the same key, other will return all
getOrDefault()  : mixed
Get a value from the container or return a default value
getOrFail()  : mixed
Get a value from the container or throw an exception.
getSilently()  : mixed
Get a value from the container or return null instead of throwing an exception
handleRequest()  : Response
hasCache()  : bool
Check if the cache has the key.
hasMacro()  : bool
Check if we have a method in the balonables
httpsOnly()  : $this
If set, only https requests shall be allowed
isBooted()  : bool
Check if the application is booted
isConsoleApp()  : bool
isDebug()  : mixed
isDevelopment()  : bool
isLinux()  : bool
isMac()  : bool
isProduction()  : bool
isRestApp()  : bool
isTesting()  : bool
isWindows()  : bool
macro()  : void
Add a new mixable to the macros
make()  : mixed
Build an entry of the container by its name.
mediaPath()  : string
The path to the resources directory.
middlewareChain()  : $this
When this is used, the closure passed must return a MiddlewareChain instance Middlewares in this chain will be added to the context and will be the only middlewares used
mixin()  : void
Mix another object into the class.
os()  : string
php()  : string
Get the PHP binary.
phpPath()  : string
phpVersion()  : string
pioniaBinary()  : string
Get the pionia cli binary.
powerUp()  : PioniaApplication
Boot the app
prepareConsole()  : void
Sync the commands from the configuration and add them to the console application
publicPath()  : string
The directory where the frontend assets are stored.
refreshEnv()  : void
resolve()  : mixed
Get any entry from the container by its id
set()  : static
Set a value in the container
setAppName()  : void
Change the core app name
setCache()  : bool
setCacheInstance()  : void
Set the cache instance to use for caching.
setEnv()  : void
setLogger()  : void
shutdown()  : void
Shutdown the application
terminate()  : void
Shutdown the application
terminated()  : void
Register the application's terminated hook listeners.
terminating()  : void
Register the application's terminating hooks.
version()  : string
welcomePageSettings()  : Arrayable
withCacheAdaptor()  : $this
Sets the Cache Adaptor the app shall use hence-forth Defaults to a filesystem adapter
withEndPoints()  : PioniaApplication|null
builtInAliases()  : Arrayable
Builtin Aliases
builtInAuthentications()  : Arrayable
Get the built-in services provided by the application.
builtInCommands()  : Arrayable
Get the built-in services provided by the application.
builtinDirectories()  : Arrayable
Builtin Aliases
builtInMiddlewares()  : Arrayable
Get the built-in services provided by the application.
builtinNameSpaces()  : Arrayable
report()  : void
bootstrapAuthentications()  : void
Adds the collected auths to the context Can also cache the authentications for future use
bootstrapCommands()  : void
Collect all the commands from the environment and the context
bootstrapMiddlewares()  : void
callBootedCallbacks()  : void
Run all booted callbacks
callBootingCallbacks()  : void
Run all booting callbacks
callTerminatedCallbacks()  : void
Run all terminated callbacks
callTerminatingCallbacks()  : void
Run all terminating callbacks
cleanCacheKey()  : string
getKeyName()  : string
Converts the key to snake case and appends the current class prefix if it does not exist.
logger()  : LoggerInterface|null
registerBaseRoutesInstance()  : void
Add the base routes instance to the context We shall be merging all routes to this instance
registerCorsInstance()  : void
Add the cors instance to the context
resolveLogger()  : $this
Set up the context logger
setDefaultCachingAdaptor()  : void
Set the default caching adaptor to use

Properties

$cachePrefix

The cache prefix to use for caching.

public string $cachePrefix = __CLASS__

$cacheTtl

The cache ttl to use for caching.

public int $cacheTtl = 60

Defaults to 60 seconds.

$context

Application container context

public ContainerInterface|Container|null $context

$bootedCallbacks

The booted callbacks

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

$bootingCallbacks

The booting callbacks, callbacks to call before the app runs

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

$macros

protected static array<string|int, mixed> $macros = []

$terminatedCallbacks

The terminated callbacks, run after terminating the application

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

$terminatingCallbacks

The terminating callbacks, run before terminating the application

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

$cacheInstance

The cache instance to use for caching.

private PioniaCache|null $cacheInstance = null

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException

__construct()

PioniaApplication constructor.

public __construct([string $applicationPath = __DIR__ ]) : mixed
Parameters
$applicationPath : string = __DIR__

addAlias()

Adds an alias to the context list of aliases

public addAlias(string $aliasName, mixed $aliasValue) : static
Parameters
$aliasName : string
$aliasValue : mixed
Return values
static

addMiddleware()

Add a single middleware to the chain

public addMiddleware(string $middleware) : $this
Parameters
$middleware : string
Return values
$this

addQueryToPool()

public addQueryToPool(string $identifier, string $query) : static
Parameters
$identifier : string
$query : string
Return values
static

alias()

Get any alias from the context

public alias(string $aliasName[, mixed|null $default = null ]) : mixed
Parameters
$aliasName : string
$default : mixed|null = null

allowedOrigins()

If set, these shall be the only addresses that can access the application

public allowedOrigins(array<string|int, mixed> $addresses) : $this
Parameters
$addresses : array<string|int, mixed>
Return values
$this

appName()

Our application name

public appName() : string
Return values
string

appRoot()

The root folder of the application.

public appRoot([string|null $path = null ][, int $levels = 3 ]) : string
Parameters
$path : string|null = null
$levels : int = 3
Return values
string

blockedOrigins()

If set, these origins shall be prevented from accessing the application

public blockedOrigins(array<string|int, mixed> $origins) : $this
Parameters
$origins : array<string|int, mixed>
Return values
$this

bootConsole()

public bootConsole([string|null $name = 'Pionia Framework' ]) : int
Parameters
$name : string|null = 'Pionia Framework'
Tags
throws
Exception
Return values
int

booted()

Register callbacks to be run after the application is booted This method can be called multiple times to add more hooks

public booted(Closure $closure) : static

Hooks here have access to the application instance

Parameters
$closure : Closure
Return values
static

booting()

Register hooks to mutate the application booting cycle.

public booting(Closure $callback) : $this

Runs before the application is booted Can be called multiple times to add more hooks.

All hooks here do not have access to the application instance

Parameters
$callback : Closure
Return values
$this

cache()

Caches the value if the value is not null.

public cache(string $key[, mixed $value = null ][, mixed $ttl = null ][, bool|null $exact = false ]) : bool|mixed
Parameters
$key : string

The key to cache

$value : mixed = null

The value to cache

$ttl : mixed = null

The time to live for the cache

$exact : bool|null = false

If passed, the key won't be parsed at all, it will be cached as is.

Return values
bool|mixed

ClearByKeys()

Clear the cache.

public ClearByKeys(array<string|int, mixed> $keys[, bool|null $exact = false ]) : bool
Parameters
$keys : array<string|int, mixed>

The keys to clear

$exact : bool|null = false

If passed, the keys won't be parsed at all

Return values
bool

contextArrAdd()

public contextArrAdd(string $contextKey, array<string|int, mixed> $dataToAdd) : void
Parameters
$contextKey : string
$dataToAdd : array<string|int, mixed>

contextHas()

Check if a value exists in the container

public contextHas(string $key) : bool
Parameters
$key : string
Return values
bool

contextMake()

Make an instance of a class from the container. This will throw an exception if the class is not found

public contextMake(string $name[, array<string|int, mixed> $parameters = [] ]) : mixed
Parameters
$name : string
$parameters : array<string|int, mixed> = []
Tags
throws
DependencyException
throws
NotFoundException

contextMakeSilently()

Create an instance of a class without throwing an exception when it fails

public contextMakeSilently(string $name[, array<string|int, mixed> $parameters = [] ]) : mixed
Parameters
$name : string
$parameters : array<string|int, mixed> = []

defaultOrFirst()

Get a database connection from the pool of connections we have

public defaultOrFirst([string|null $name = null ]) : mixed

If a name is passed, then we try to grab that name

Parameters
$name : string|null = null
Tags
throws
Throwable

deleteCache()

Delete the cache for the key.

public deleteCache(string $key[, bool $exact = false ]) : bool
Parameters
$key : string

The key to delete

$exact : bool = false

If passed, the key won't be parsed at all

Return values
bool

dispatch()

Dispatches an event from anywhere in the application

public dispatch(object $event, string $name) : void
Parameters
$event : object
$name : string

envPath()

public envPath([string|null $path = null ]) : string
Parameters
$path : string|null = null
Return values
string

flushMacros()

Remove all the macros we had registered

public static flushMacros() : void

formatCommandString()

Format the given command as a fully-qualified executable command.

public static formatCommandString(string $string) : string
Parameters
$string : string
Return values
string

getCache()

public getCache( $key[, bool|null $exact = false ]) : mixed
Parameters
$key :
$exact : bool|null = false

getDirFor()

Get the directory for a given alias

public getDirFor(string $aliasName) : string|null
Parameters
$aliasName : string
Return values
string|null

getDiscoveredConnections()

Get the discovered database connections that are available in our environment

public getDiscoveredConnections() : Arrayable
Return values
Arrayable

getEnv()

Get all the environment variables or the value of a single key Will check in the $_ENV, $_SERVER, container, and in the local env array for the same key, other will return all

public getEnv([string|null $key = null ][, mixed $default = null ]) : PioniaApplicationType
Parameters
$key : string|null = null
$default : mixed = null
Return values
PioniaApplicationType

getOrDefault()

Get a value from the container or return a default value

public getOrDefault(string $key, mixed $default) : mixed
Parameters
$key : string
$default : mixed

getOrFail()

Get a value from the container or throw an exception.

public getOrFail(string $key) : mixed
Parameters
$key : string
Tags
see
PioniaApplication::resolve()

for similar functionality on the application instance

throws
ContainerExceptionInterface
throws
DependencyException
throws
NotFoundException
throws
NotFoundExceptionInterface

getSilently()

Get a value from the container or return null instead of throwing an exception

public getSilently(mixed $key) : mixed
Parameters
$key : mixed

hasCache()

Check if the cache has the key.

public hasCache( $key[, bool|null $exact = false ]) : bool

Will not throw an exception if the key is not set or the cache is not activated.

Parameters
$key :
$exact : bool|null = false
Return values
bool

hasMacro()

Check if we have a method in the balonables

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

httpsOnly()

If set, only https requests shall be allowed

public httpsOnly([bool $httpsOnly = true ]) : $this
Parameters
$httpsOnly : bool = true
Return values
$this

isBooted()

Check if the application is booted

public isBooted() : bool
Return values
bool

isDevelopment()

public isDevelopment() : bool
Return values
bool

If we are in development mode

macro()

Add a new mixable to the macros

public static macro(string $key,  $value) : void
Parameters
$key : string
$value :

make()

Build an entry of the container by its name.

public make(string $name[, array<string|int, mixed> $parameters = [] ]) : mixed

This method behave like resolve() except resolves the entry again every time. For example if the entry is a class then a new instance will be created each time.

This method makes the container behave like a factory.

Parameters
$name : string
$parameters : array<string|int, mixed> = []
Tags
throws
DependencyException
throws
NotFoundException

mediaPath()

The path to the resources directory.

public mediaPath() : string
Return values
string

middlewareChain()

When this is used, the closure passed must return a MiddlewareChain instance Middlewares in this chain will be added to the context and will be the only middlewares used

public middlewareChain(Closure $closure) : $this
Parameters
$closure : Closure
Return values
$this

mixin()

Mix another object into the class.

public static mixin(object $mixin[, bool $replace = true ]) : void
Parameters
$mixin : object
$replace : bool = true
Tags
throws
ReflectionException

php()

Get the PHP binary.

public static php() : string
Return values
string

phpPath()

public phpPath() : string
Return values
string

phpVersion()

public phpVersion() : string
Return values
string

pioniaBinary()

Get the pionia cli binary.

public static pioniaBinary() : string
Return values
string

prepareConsole()

Sync the commands from the configuration and add them to the console application

public prepareConsole() : void

publicPath()

The directory where the frontend assets are stored.

public publicPath([ $path = null ]) : string
Parameters
$path : = null
Return values
string

resolve()

Get any entry from the container by its id

public resolve(string $id) : mixed

This is an acronym of getOrFail which throws an exception if the entry is not found

Parameters
$id : string
Tags
see
getOrFail()
throws
DependencyException
throws
NotFoundException

set()

Set a value in the container

public set(string $name, mixed $value) : static
Parameters
$name : string
$value : mixed
Return values
static

setAppName()

Change the core app name

public setAppName( $name) : void
Parameters
$name :

setCache()

public setCache(string $key, mixed $value[, mixed $ttl = null ][, bool|null $exact = false ]) : bool
Parameters
$key : string
$value : mixed
$ttl : mixed = null
$exact : bool|null = false
Return values
bool

setCacheInstance()

Set the cache instance to use for caching.

public setCacheInstance(PioniaCache|null $cache) : void
Parameters
$cache : PioniaCache|null

setEnv()

public setEnv(string $key, Arrayable|null $env[, bool|null $override = true ]) : void
Parameters
$key : string
$env : Arrayable|null
$override : bool|null = true

setLogger()

public setLogger(LoggerInterface $logger) : void
Parameters
$logger : LoggerInterface

terminate()

Shutdown the application

public terminate([int $status = 1 ]) : void
Parameters
$status : int = 1

terminated()

Register the application's terminated hook listeners.

public terminated(Closure $closure) : void

All logic that needs to run after the application is terminated Can be called multiple times to add more hooks

Hooks here do not have access to the application instance

Parameters
$closure : Closure

terminating()

Register the application's terminating hooks.

public terminating(Closure $callback) : void

All logic that needs to run before the application is terminated Can be called multiple times to add more hooks

Hooks here have access to the application instance

Parameters
$callback : Closure

version()

public version() : string
Return values
string

The version of the application

withCacheAdaptor()

Sets the Cache Adaptor the app shall use hence-forth Defaults to a filesystem adapter

public withCacheAdaptor(callable $cacheAdaptorResolver) : $this

All Symfony cache adaptors are supported, even a custom one can be added as long as it supports the PSR-16 CacheInterface

The callable receives both the application and the env as arguments

Parameters
$cacheAdaptorResolver : callable
Return values
$this

report()

protected report(string $format, string $message[, array<string|int, mixed>|null $data = [] ]) : void
Parameters
$format : string
$message : string
$data : array<string|int, mixed>|null = []

bootstrapAuthentications()

Adds the collected auths to the context Can also cache the authentications for future use

private bootstrapAuthentications() : void

bootstrapCommands()

Collect all the commands from the environment and the context

private bootstrapCommands() : void

cleanCacheKey()

private cleanCacheKey(string $key) : string
Parameters
$key : string
Return values
string

getKeyName()

Converts the key to snake case and appends the current class prefix if it does not exist.

private getKeyName(string $key) : string
Parameters
$key : string
Return values
string

logger()

private logger() : LoggerInterface|null
Return values
LoggerInterface|null

registerBaseRoutesInstance()

Add the base routes instance to the context We shall be merging all routes to this instance

private registerBaseRoutesInstance() : void

registerCorsInstance()

Add the cors instance to the context

private registerCorsInstance() : void

resolveLogger()

Set up the context logger

private resolveLogger() : $this
Return values
$this

setDefaultCachingAdaptor()

Set the default caching adaptor to use

private setDefaultCachingAdaptor() : void

        
On this page

Search results