Utilities Helpers

The Utilities Helpers are lightweight functions that provide versatile utilities for development and runtime tasks. They include JSON output for debugging, IP address retrieval, view rendering within modules, file info extraction, array and object sorting by properties, and checks for Trongate MX requests.

api_auth()

Authenticate API requests and validate access based on API rules.

block_url()

Blocks direct browser access to a module or a specific module-method combination,
while allowing unrestricted internal access from PHP code.
This function provides fine-grained control over URL access, allowing you to protect
entire modules or individual methods depending on where you call it.

block_url_invocation()

Blocks direct browser access to an entire module while allowing unrestricted internal
access from PHP code. This function is designed for utility and service modules that
should never be callable via a URL, such as payment processors, email handlers, or
background workers.

display()

Displays a content view within a template. This helper function is used inside template files to inject the actual page content at a specific location. It automatically detects the view module and view file from the provided data array, builds the path to the view file, extracts the data variables, and includes the view. If the specified view file cannot be found, it displays a helpful error message indicating the expected file path.

from_trongate_mx()

Checks if the HTTP request has been invoked by Trongate MX. This function inspects the HTTP headers to determine if the request contains a specific header indicating that it originated from Trongate MX. It is useful for distinguishing requests made from Trongate MX from those made by other sources.

ip_address()

Retrieves the client's IP address.

json()

Outputs the given data as JSON in a prettified format, suitable for debugging and visualization. This function is especially useful during development for inspecting data structures in a readable JSON format directly in the browser. It optionally allows terminating the script immediately after output, which is useful in API development for stopping further processing.

load()

Loads a template file with optional data for use within the template.

return_file_info()

Extracts file name and extension from a given file path.

sort_by_property()

Sorts an array of associative arrays by a specified property. This function is useful when you need to organize data within an array of associative arrays based on one of the properties in each array element. The sorting can be done in either ascending or descending order.

sort_rows_by_property()

Sorts an array of objects by a specified property. This function is useful when you need to organize a collection of objects based on one of their properties. The sorting can be performed in either ascending or descending order.