Core_helper
Class Core_helper in PHPFast provides several utility functions to manage helpers, system configurations, server information, and environment variables in a PHP application.
Functions Helper in Core
load_helpers()
load_helpers()
Loads helper files dynamically from either the system or application directories.
function load_helpers(array $helpers = []) {
How It Works:
Uses a global variable
$fast_helpers
to track loaded helpers.Checks if the helper is already loaded to avoid redundant imports.
Searches for the helper file in:
ROOT_PATH/system/Helpers/
ROOT_PATH/application/Helpers/
If the file exists, it is included (
require_once
), otherwise, it throws an exception.
Example:
load_helpers(['form', 'url']); // Loads form_helper.php and url_helper.php
DateTime()
DateTime()
Returns the current date and time in the YYYY-MM-DD HH:MM:SS
format.
function DateTime() {
return date('Y-m-d H:i:s');
}
Example:
echo DateTime();
// Output: 2025-03-01 12:34:56
version_php()
version_php()
Returns the current PHP version.
Example:
echo version_php();
// Output: 8.3.16
dir_writable()
dir_writable()
Checks if a given directory exists and is writable.
Returns
true
if writable, otherwisefalse
.
Example:
echo dir_writable('/writable/uploads') ? "Writable" : "Not Writable";
server_info()
server_info()
Returns an array of server information, including:
PHP version
Web server software
Document root
Server name
Server protocol
Example:
[
[php_version] => 8.3.16
[server_software] => nginx/1.27.3
[document_root] => C:/laragon/www/cms/public
[server_name] => cms.test
[server_protocol] => HTTP/1.1
]
random_string()
random_string()
Generates a random alphanumeric string of the specified length.
function random_string($length = 10) {}
Example:
echo random_string(12);
// Output: A1b2C3d4E5F6
config()
config()
Loads configuration values from a specified file.
function config($key = '', $file = 'Config') {}
Reads the
/application/Config/Config.php
file and returns the requested setting.Uses a static
$config
array to cache values for performance.
Example:
$siteName = config('site_name'); // Loads the site_name from Config.php.
option()
option()
Retrieves an option value from the
Options.php
config file or from the database.If the key is not found in the file, it queries the database for the value.
function option($key, $lang = LANG) {}
Example:
$siteTitle = option('site_title');
// Gets the site title from the options table or configuration file.
option_set()
option_set()
Updates an option value in the configuration file (
Options.php
).Supports multi-language values if
$lang
is specified.
function option_set($key, $value, $lang = '') {}
Loads the
Options.php
file.Updates the key-value pair.
Saves the new values back to the file.
Example:
option_set('site_title', 'PHPFast site');
// Updates the site_title value in Options.php.
echo option('site_title');
// Ouput: PHPFast site
env()
env()
Retrieves environment variables from the system or .env
file.
function env($key, $default = null) {}
First, checks if the value exists in cache (
$env_cache
).If not found, retrieves it using
getenv()
.Cleans the value to prevent security issues (
htmlspecialchars
).Converts "true", "false", "null" strings into actual boolean values.
Example:
$dbHost = env('DB_HOST', 'localhost');
// Retrieves the database host from environment variables.
_bytes()
_bytes()
Converts a storage unit string (e.g., 2G
, 512M
, 128K
) into bytes.
function _bytes($size) {}
Extracts the unit (G, M, K).
Converts it into bytes accordingly.
Example:
echo _bytes('2G');
// Output: 2147483648
Function
Purpose
load_helpers()
Load helper files dynamically.
DateTime()
Get the current date and time.
version_php()
Retrieve the PHP version.
dir_writable()
Check if a directory is writable.
server_info()
Get server details (PHP version, web server, etc.).
random_string()
Generate a random alphanumeric string.
config()
Retrieve system configuration settings.
option()
Fetch system options from a file or database.
option_set()
Update an option value in Options.php
.
env()
Retrieve environment variables from .env
or system.
_bytes()
Convert storage units (G, M, K) to bytes.
Last updated
Was this helpful?