Menu

## 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

helpers.php : 117
`public mixed BASEPATH = dirname(__DIR__, 2)`

### Functions

#### tap()

helpers.php : 33

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

template

  TValue

##### Return values

HighOrderTapProxy|TValue

#### arr()

helpers.php : 52

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

Arrayable

#### env()

helpers.php : 64

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()

helpers.php : 76

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()

helpers.php : 98

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

BaseResponse

#### app()

helpers.php : 109

Helper function to return the application instance

`app() : PioniaApplication`

##### Return values

PioniaApplication

#### container()

helpers.php : 128

Helper function to return the application container

`container() : Container`

##### Return values

Container

#### db()

helpers.php : 143

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

throws
  Exception

##### Return values

Porm|null

#### table()

helpers.php : 163

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

throws
  Exception
example

      table('users')->where(['username' => 'Pionia'])->get();

##### Return values

Porm —

The porm instance for further chaining of queries

#### alias()

helpers.php : 175
`alias(mixed $key) : mixed`

##### Parameters

$key : mixed

#### directoryFor()

helpers.php : 185

Get any directory from the application container

`directoryFor(mixed $key) : mixed`

##### Parameters

$key : mixed

#### yesNo()

helpers.php : 200

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

string

#### asBool()

helpers.php : 211

convert a value to a boolean

`asBool(mixed $value) : array<string|int, mixed>`

##### Parameters

$value : mixed

##### Return values

array<string|int, mixed>

#### writeIniFile()

helpers.php : 226

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

bool

#### logger()

helpers.php : 292

Get the logger instance from the application container

`logger() : LoggerInterface`

##### Return values

LoggerInterface

#### addIniSection()

helpers.php : 313

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

bool

#### cachedResponse()

helpers.php : 345

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

note

  This function is only available if the service has caching enabled

note

  This is still under rigorous tests

##### Return values

BaseResponse —

The cached response / the response you passed. It's not tampered with

#### recached()

helpers.php : 376

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

note

  This function is only useful if the service has caching enabled

##### Return values

BaseResponse —

The cached response / the response you passed. It's not tampered with

#### render()

helpers.php : 420

Render a template file from the templates folder.

`render( $file[, array<string|int, mixed>|null $data = [] ]) : void`

##### Parameters

$file :
$data : array<string|int, mixed>|null = []

#### parseHtml()

helpers.php : 435

Get all the builtins

`parseHtml( $file[, array<string|int, mixed>|null $data = [] ]) : array<string|int, mixed>`

##### Parameters

$file :
$data : array<string|int, mixed>|null = []

##### Return values

array<string|int, mixed>

#### asset()

helpers.php : 448

Get the asset path

`asset( $file[, string|null $dir = null ]) : string|null`

##### Parameters

$file :
$dir : string|null = null

##### Return values

string|null

#### blank()

helpers.php : 474

Determine if the given value is "blank".

`blank(mixed $value) : bool`

##### Parameters

$value : mixed

##### Tags

phpstan-assert-if-false

  !=null|'' $value

phpstan-assert-if-true

  !=numeric|bool $value

##### Return values

bool

#### validate()

helpers.php : 511

Validate data

`validate(string $field, Arrayable|Request|Service $data) : Validator`

##### Parameters

$field : string
$data : Arrayable|Request|Service

##### Return values

Validator

#### toCamelCase()

helpers.php : 526

Convert a string to camel case

`toCamelCase(string $value) : string`

##### Parameters

$value : string

##### Return values

string

#### toSnakeCase()

helpers.php : 536

Convert a string to snake case

`toSnakeCase(string $value) : string`

##### Parameters

$value : string

##### Return values

string

#### classify()

helpers.php : 546

Convert a string to a class name like format

`classify(string $value) : string`

##### Parameters

$value : string

##### Return values

string

#### arrayToString()

helpers.php : 556

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

string

#### slugify()

helpers.php : 566

Convert a string to a slug-like format

`slugify(string $value) : string`

##### Parameters

$value : string

##### Return values

string

#### singularize()

helpers.php : 576

Convert a string to a singular form

`singularize(string $word) : string`

##### Parameters

$word : string

##### Return values

string

#### pluralize()

helpers.php : 586

Convert a string to a plural form

`pluralize(string $word) : string`

##### Parameters

$word : string

##### Return values

string

#### capitalize()

helpers.php : 596

Capitalize a string

`capitalize(string $phrase) : string`

##### Parameters

$phrase : string

##### Return values

string

#### jsonify()

helpers.php : 606

Convert anything to a json string

`jsonify(mixed $phrase) : string`

##### Parameters

$phrase : mixed

##### Return values

string

#### flatten()

helpers.php : 619

Flatten an array

`flatten(array<string|int, mixed> $flatten) : array<string|int, mixed>`

##### Parameters

$flatten : array<string|int, mixed>

##### Tags

example

  flatten(['a', 'b', ['c', 'd']]) => ['a', 'b', 'c', 'd']

##### Return values

array<string|int, mixed>

#### is_cached_in()

helpers.php : 627
`is_cached_in(mixed $keyCached, mixed $keyToCheck) : bool`

##### Parameters

$keyCached : mixed
$keyToCheck : mixed

##### Return values

bool

## Search results