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_helpersto 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.phpDateTime()
DateTime()Returns the current date and time in the YYYY-MM-DD HH:MM:SS format.
Example:
version_php()
version_php()Returns the current PHP version.
Example:
dir_writable()
dir_writable()Checks if a given directory exists and is writable.
Returns
trueif writable, otherwisefalse.
Example:
server_info()
server_info()Returns an array of server information, including:
PHP version
Web server software
Document root
Server name
Server protocol
Example:
random_string()
random_string()Generates a random alphanumeric string of the specified length.
Example:
config()
config()Loads configuration values from a specified file.
Reads the
/application/Config/Config.phpfile and returns the requested setting.Uses a static
$configarray to cache values for performance.
Example:
option()
option()Retrieves an option value from the
Options.phpconfig file or from the database.If the key is not found in the file, it queries the database for the value.
Example:
option_set()
option_set()Updates an option value in the configuration file (
Options.php).Supports multi-language values if
$langis specified.
Loads the
Options.phpfile.Updates the key-value pair.
Saves the new values back to the file.
Example:
env()
env()Retrieves environment variables from the system or .env file.
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:
_bytes()
_bytes()Converts a storage unit string (e.g., 2G, 512M, 128K) into bytes.
Extracts the unit (G, M, K).
Converts it into bytes accordingly.
Example:
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?