Heratio Framework API Reference

CommonHelper
in package

Common utility functions used across AHG plugins.

Consolidates frequently repeated code patterns.

Table of Contents

Methods

dateAfter()  : string
Get date relative to today.
escape()  : string
Escape HTML entities.
filterNonBlank()  : array<string|int, mixed>
Filter array to only include non-blank values.
filterNonNull()  : array<string|int, mixed>
Filter array to only include non-null values.
formatReference()  : string
Format a reference number with prefix and sequence.
get()  : mixed
Safely get array value with default.
getClientIp()  : string|null
Get client IP address safely.
getCurrentUserId()  : int|null
Get current user ID from Symfony context.
getCurrentUsername()  : string|null
Get current username from Symfony context.
getUserAgent()  : string|null
Get user agent safely (truncated).
isBlank()  : bool
Check if a value is empty or whitespace only.
jsonDecode()  : mixed
Safely JSON decode with error handling.
jsonEncode()  : string|null
Safely JSON encode with error handling.
now()  : string
Get current datetime in MySQL format.
nullIfBlank()  : mixed
Get non-blank value or null.
snakeKeys()  : array<string|int, mixed>
Convert array keys to snake_case.
timestamps()  : array<string|int, mixed>
Build standard timestamps array for insert operations.
today()  : string
Get current date in MySQL format.
touchTimestamp()  : array<string|int, mixed>
Build updated_at timestamp for update operations.
truncate()  : string
Truncate string safely with ellipsis.
uuid()  : string
Generate a UUID v4.

Methods

dateAfter()

Get date relative to today.

public static dateAfter(int $days) : string
Parameters
$days : int
Return values
string

escape()

Escape HTML entities.

public static escape(string|null $string) : string
Parameters
$string : string|null
Return values
string

filterNonBlank()

Filter array to only include non-blank values.

public static filterNonBlank(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

filterNonNull()

Filter array to only include non-null values.

public static filterNonNull(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

formatReference()

Format a reference number with prefix and sequence.

public static formatReference(string $prefix, string $code, int $sequence[, string $separator = '-' ]) : string
Parameters
$prefix : string
$code : string
$sequence : int
$separator : string = '-'
Return values
string

get()

Safely get array value with default.

public static get(array<string|int, mixed> $array, string $key[, mixed $default = null ]) : mixed
Parameters
$array : array<string|int, mixed>
$key : string
$default : mixed = null

getClientIp()

Get client IP address safely.

public static getClientIp() : string|null
Return values
string|null

getCurrentUserId()

Get current user ID from Symfony context.

public static getCurrentUserId() : int|null
Return values
int|null

getCurrentUsername()

Get current username from Symfony context.

public static getCurrentUsername() : string|null
Return values
string|null

getUserAgent()

Get user agent safely (truncated).

public static getUserAgent([int $maxLength = 500 ]) : string|null
Parameters
$maxLength : int = 500
Return values
string|null

isBlank()

Check if a value is empty or whitespace only.

public static isBlank(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

jsonDecode()

Safely JSON decode with error handling.

public static jsonDecode(string|null $json[, bool $assoc = true ]) : mixed
Parameters
$json : string|null
$assoc : bool = true

jsonEncode()

Safely JSON encode with error handling.

public static jsonEncode(mixed $data) : string|null
Parameters
$data : mixed
Return values
string|null

now()

Get current datetime in MySQL format.

public static now() : string
Return values
string

nullIfBlank()

Get non-blank value or null.

public static nullIfBlank(mixed $value) : mixed
Parameters
$value : mixed

snakeKeys()

Convert array keys to snake_case.

public static snakeKeys(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
Return values
array<string|int, mixed>

timestamps()

Build standard timestamps array for insert operations.

public static timestamps() : array<string|int, mixed>
Return values
array<string|int, mixed>

today()

Get current date in MySQL format.

public static today() : string
Return values
string

touchTimestamp()

Build updated_at timestamp for update operations.

public static touchTimestamp() : array<string|int, mixed>
Return values
array<string|int, mixed>

truncate()

Truncate string safely with ellipsis.

public static truncate(string $string, int $length[, string $suffix = '...' ]) : string
Parameters
$string : string
$length : int
$suffix : string = '...'
Return values
string

uuid()

Generate a UUID v4.

public static uuid() : string
Return values
string

        
On this page

Search results