Functions
True\Functions is the framework's grab-bag of static utility methods — encryption, URL parsing, browser detection, file-size formatting, and a few common string/array helpers. Reach for it instead of rolling your own when one of these patterns comes up.
Encryption & tokens
$encrypted = True\Functions::encrypt('Hello World!', 'mySecretKey');
$plain = True\Functions::decrypt($encrypted, 'mySecretKey'); // null on failure
$token = True\Functions::genToken(); // default 64 chars
$shorter = True\Functions::genToken(32);
- encrypt / decrypt — AES-128-CBC with a Base64-encoded payload.
- genToken — cryptographically secure random token.
URL helpers
echo True\Functions::host();
// => https://www.example.com
$u = True\Functions::parseUrl('https://user:pass@www.example.com:8080/path?query=123#fragment');
// Returns an object of URL components. Pass `true` as the 2nd arg to also
// include the port and user-credentials parts.
echo True\Functions::getLastPartOfURL('https://www.example.com/path/to/page');
// => "page"
// Pass `true` instead of a URL to use the current REQUEST_URI.
Browser detection
$browser = True\Functions::getBrowser();
// => ['name' => 'Chrome', 'version' => '127']
if (True\Functions::supportsGrid($browser)) {
echo 'CSS Grid is supported!';
}
Numbers & sizes
echo True\Functions::humanFileSize(1048576); // => "1.00MB"
echo True\Functions::humanFileSize(1048576, 'KB'); // force the unit
echo True\Functions::dollars(1234.56); // => "$1,234.56"
Strings & arrays
if (True\Functions::contains('Hello World', 'world')) {
// case-insensitive by default; pass `false` as 3rd arg for case-sensitive
}
$keys = ['name', 'email'];
$array = ['name' => 'John', 'email' => 'john@example.com'];
if (True\Functions::keys_exist($keys, $array)) {
// all requested keys are present
}
API quick reference
| Method | Returns |
|---|---|
encrypt(string $str, string $key): string | Base64-encoded ciphertext. |
decrypt(string $str, string $key): ?string | Plaintext, or null on failure. |
genToken(int $length = 64): string | Secure random token. |
host(): string | Scheme + host of the current request. |
parseUrl(string $url, bool $extra = false): object | Object of URL components. |
getLastPartOfURL(string|bool $str): string | Last path segment. |
getBrowser(): array | ['name', 'version'] from the UA string. |
supportsGrid(array $params): bool | Whether the given browser supports CSS Grid. |
humanFileSize(int $size, string $unit = ''): string | Human-readable size string. |
contains(string $haystack, string $needle, bool $ci = true): bool | Substring check. |
keys_exist(array $keys, array $array): bool | All-keys-present check. |
dollars(float $amount): string | USD-formatted string. |