helpers.php
Table of Contents
Constants
- BASEPATH = dirname(__DIR__, 2)
Functions
- tap() : HighOrderTapProxy|TValue
- Call the given Closure with the given value then return the value.
- arr() : Arrayable
- Get an item from an array using "dot" notation.
- env() : mixed
- Get an item from the environment. Or default if it does not exist.
- setEnv() : void
- Adds a temporary key-value to the environment.
- response() : BaseResponse
- Helper function to return a response
- app() : PioniaApplication
- Helper function to return the application instance
- container() : Container
- Helper function to return the application container
- db() : Porm|null
- Run any pionia-powered queries
- table() : Porm
- Run any pionia-powered queries
- alias() : mixed
- directoryFor() : mixed
- Get any directory from the application container
- yesNo() : string
- This function returns a yes or no phrase based on the condition
- asBool() : array<string|int, mixed>
- convert a value to a boolean
- writeIniFile() : bool
- Write an ini configuration file This writes to the file in a lock-safe manner
- logger() : LoggerInterface
- Get the logger instance from the application container
- addIniSection() : bool
- This function adds a new section to an ini file We generally use this to generate and add new sections to the generated.ini file which holds settings for the auto-generated files
- cachedResponse() : BaseResponse
- This function caches a response if the service has caching enabled.
- recached() : BaseResponse
- Acronym for `cachedResponse` function but with more readable arguments
- render() : void
- Render a template file from the templates folder.
- parseHtml() : array<string|int, mixed>
- Get all the builtins
- asset() : string|null
- Get the asset path
- blank() : bool
- Determine if the given value is "blank".
- validate() : Validator
- Validate data
- toCamelCase() : string
- Convert a string to camel case
- toSnakeCase() : string
- Convert a string to snake case
- classify() : string
- Convert a string to a class name like format
- arrayToString() : string
- Convert an array to a string
- slugify() : string
- Convert a string to a slug-like format
- singularize() : string
- Convert a string to a singular form
- pluralize() : string
- Convert a string to a plural form
- capitalize() : string
- Capitalize a string
- jsonify() : string
- Convert anything to a json string
- flatten() : array<string|int, mixed>
- Flatten an array
- is_cached_in() : bool
Constants
BASEPATH
public
mixed
BASEPATH
= dirname(__DIR__, 2)
Functions
tap()
Call the given Closure with the given value then return the value.
tap(TValue $value[, callable(TValue): mixed|null $callback = null ]) : HighOrderTapProxy|TValue
Value returned is not transformed by the closure.
Parameters
- $value : TValue
- $callback : callable(TValue): mixed|null = null
Tags
Return values
HighOrderTapProxy|TValuearr()
Get an item from an array using "dot" notation.
arr(array<string|int, mixed>|null $array) : Arrayable
Parameters
- $array : array<string|int, mixed>|null
Return values
Arrayableenv()
Get an item from the environment. Or default if it does not exist.
env([string|null $key = null ][, mixed $default = null ]) : mixed
If both the key and the default value are null, the function should return the entire environment.
Parameters
- $key : string|null = null
- $default : mixed = null
setEnv()
Adds a temporary key-value to the environment.
setEnv(string $key, mixed $value) : void
This can only be retrieved using the env
function.
Parameters
- $key : string
- $value : mixed
response()
Helper function to return a response
response([ $returnCode = 0 ][, string|null $returnMessage = null ][, mixed $returnData = null ][, mixed $extraData = null ]) : BaseResponse
Parameters
- $returnCode : = 0
-
int
- $returnMessage : string|null = null
- $returnData : mixed = null
- $extraData : mixed = null
Return values
BaseResponseapp()
Helper function to return the application instance
app() : PioniaApplication
Return values
PioniaApplicationcontainer()
Helper function to return the application container
container() : Container
Return values
Containerdb()
Run any pionia-powered queries
db(string $tableName[, string|null $tableAlias = null ][, string|null $using = null ]) : Porm|null
Parameters
- $tableName : string
-
The name of the table to connect to
- $tableAlias : string|null = null
- $using : string|null = null
Tags
Return values
Porm|nulltable()
Run any pionia-powered queries
table(string $tableName[, string|null $tableAlias = null ][, string|null $using = null ]) : Porm
Parameters
- $tableName : string
-
The name of the table to connect to
- $tableAlias : string|null = null
-
The alias to use for the table provided
- $using : string|null = null
-
The connection to use
Tags
Return values
Porm —The porm instance for further chaining of queries
alias()
alias(mixed $key) : mixed
Parameters
- $key : mixed
directoryFor()
Get any directory from the application container
directoryFor(mixed $key) : mixed
Parameters
- $key : mixed
yesNo()
This function returns a yes or no phrase based on the condition
yesNo(bool $condition[, string|null $yesPhrase = 'Yes' ][, string|null $noPhrase = 'No' ]) : string
Parameters
- $condition : bool
-
The condition to check
- $yesPhrase : string|null = 'Yes'
-
The phrase to return if the condition is true
- $noPhrase : string|null = 'No'
-
The phrase to return if the condition is false
Return values
stringasBool()
convert a value to a boolean
asBool(mixed $value) : array<string|int, mixed>
Parameters
- $value : mixed
Return values
array<string|int, mixed>writeIniFile()
Write an ini configuration file This writes to the file in a lock-safe manner
writeIniFile(string $file[, array<string|int, mixed> $array = [] ]) : bool
Parameters
- $file : string
- $array : array<string|int, mixed> = []
Return values
boollogger()
Get the logger instance from the application container
logger() : LoggerInterface
Return values
LoggerInterfaceaddIniSection()
This function adds a new section to an ini file We generally use this to generate and add new sections to the generated.ini file which holds settings for the auto-generated files
addIniSection(string $section[, array<string|int, mixed>|null $keyValueToAppend = [] ][, string $iniFile = 'generated.ini' ]) : bool
This function will create the file if it does not exist, add the section if it does not exist or update the section if it exists
Parameters
- $section : string
- $keyValueToAppend : array<string|int, mixed>|null = []
- $iniFile : string = 'generated.ini'
Return values
boolcachedResponse()
This function caches a response if the service has caching enabled.
cachedResponse(Service $instance, BaseResponse $response[, mixed $ttl = 60 ]) : BaseResponse
Cached key is of the format service_action
in camel case.
If no ttl is defined, caching will happen for only 60 seconds
Parameters
- $instance : Service
-
The service we are currently in, just pass
this
here! - $response : BaseResponse
-
The response object to cache, you can use
response()
for this! - $ttl : mixed = 60
-
The time to live for the cache, defaults to 60 seconds
Tags
Return values
BaseResponse —The cached response / the response you passed. It's not tampered with
recached()
Acronym for `cachedResponse` function but with more readable arguments
recached(Service $instance[, int|null $returnCode = 0 ][, string|null $returnMessage = null ][, mixed|null $returnData = null ][, mixed|null $extraData = null ][, mixed $ttl = 60 ]) : BaseResponse
Parameters
- $instance : Service
-
The service we are currently in, just pass
this
here - $returnCode : int|null = 0
-
The return code for the response, defaults to 0
- $returnMessage : string|null = null
-
The return message for the response, defaults to null
- $returnData : mixed|null = null
-
The return data for the response, defaults to null
- $extraData : mixed|null = null
-
The extra data for the response, defaults to null
- $ttl : mixed = 60
-
The time to live for the cache, defaults to 60 seconds
Tags
Return values
BaseResponse —The cached response / the response you passed. It's not tampered with
render()
Render a template file from the templates folder.
render( $file[, array<string|int, mixed>|null $data = [] ]) : void
Parameters
parseHtml()
Get all the builtins
parseHtml( $file[, array<string|int, mixed>|null $data = [] ]) : array<string|int, mixed>
Parameters
Return values
array<string|int, mixed>asset()
Get the asset path
asset( $file[, string|null $dir = null ]) : string|null
Parameters
Return values
string|nullblank()
Determine if the given value is "blank".
blank(mixed $value) : bool
Parameters
- $value : mixed
Tags
Return values
boolvalidate()
Validate data
validate(string $field, Arrayable|Request|Service $data) : Validator
Parameters
- $field : string
- $data : Arrayable|Request|Service
Return values
ValidatortoCamelCase()
Convert a string to camel case
toCamelCase(string $value) : string
Parameters
- $value : string
Return values
stringtoSnakeCase()
Convert a string to snake case
toSnakeCase(string $value) : string
Parameters
- $value : string
Return values
stringclassify()
Convert a string to a class name like format
classify(string $value) : string
Parameters
- $value : string
Return values
stringarrayToString()
Convert an array to a string
arrayToString(array<string|int, mixed> $value[, string|null $separator = ',' ]) : string
Parameters
- $value : array<string|int, mixed>
- $separator : string|null = ','
Return values
stringslugify()
Convert a string to a slug-like format
slugify(string $value) : string
Parameters
- $value : string
Return values
stringsingularize()
Convert a string to a singular form
singularize(string $word) : string
Parameters
- $word : string
Return values
stringpluralize()
Convert a string to a plural form
pluralize(string $word) : string
Parameters
- $word : string
Return values
stringcapitalize()
Capitalize a string
capitalize(string $phrase) : string
Parameters
- $phrase : string
Return values
stringjsonify()
Convert anything to a json string
jsonify(mixed $phrase) : string
Parameters
- $phrase : mixed
Return values
stringflatten()
Flatten an array
flatten(array<string|int, mixed> $flatten) : array<string|int, mixed>
Parameters
- $flatten : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>is_cached_in()
is_cached_in(mixed $keyCached, mixed $keyToCheck) : bool
Parameters
- $keyCached : mixed
- $keyToCheck : mixed