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

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

Returns the current date and time in the YYYY-MM-DD HH:MM:SS format.

Example:

version_php()

Returns the current PHP version.

Example:

dir_writable()

  • Checks if a given directory exists and is writable.

  • Returns true if writable, otherwise false.

Example:

server_info()

  • Returns an array of server information, including:

    • PHP version

    • Web server software

    • Document root

    • Server name

    • Server protocol

Example:

random_string()

Generates a random alphanumeric string of the specified length.

Example:

config()

Loads configuration values from a specified file.

  • Reads the /application/Config/Config.php file and returns the requested setting.

  • Uses a static $config array to cache values for performance.

Example:

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.

Example:

option_set()

  • Updates an option value in the configuration file (Options.php).

  • Supports multi-language values if $lang is specified.

  • Loads the Options.php file.

  • Updates the key-value pair.

  • Saves the new values back to the file.

Example:

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

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?