phpEZ
Table of Contents
Packages
Classes
- StringHTMLContent
- Base class for custom response types with specific Content-Type handling.
- Redirect
- Base class for custom response types with specific Content-Type handling.
- ObjDef
- Base class for class-level attributes in the phpEZ framework.
Traits
- Sexable
- Trait Sexable: Provides session persistence helpers for Model/Obj classes via Sex.
Constants
- BASE_PATH : mixed = \realpath(__DIR__) . \DIRECTORY_SEPARATOR
- Absolute path to the framework base directory.
Functions
- glb() : mixed
- Safely retrieve a global variable by name.
- rmbasepath() : mixed
- Convert a file path to relative, human-readable form.
- excClean() : mixed
- Clean and format a stack trace entry for JSON output.
- final_json() : never
- Sends a final JSON response and terminates the request.
- require_blank_ctx() : void
- Load a PHP file in a clean context with access to the App instance.
- html() : StringHTMLContent
- Helper function to create a StringHTMLContent response.
- redirect() : Redirect
- Helper function to create a Redirect response.
Constants
BASE_PATH
Absolute path to the framework base directory.
public
mixed
BASE_PATH
= \realpath(__DIR__) . \DIRECTORY_SEPARATOR
Used for relative path rendering in debug output (converted to ~/). Prevents exposing full server paths in error responses.
Tags
Functions
glb()
Safely retrieve a global variable by name.
glb(string $vname[, mixed $default = null ]) : mixed
Avoids PHP notices for undefined globals and provides a consistent interface for accessing framework globals like $debug.
Usage:
$debug = glb('debug', false); // Get $debug or default to false
$startup = glb('_startup'); // Get $_startup or null
Parameters
- $vname : string
-
The variable name (without $).
- $default : mixed = null
-
Default value if the global is not set. Defaults to null.
Return values
mixed —The global variable value or $default.
rmbasepath()
Convert a file path to relative, human-readable form.
rmbasepath(mixed $r) : mixed
Replaces BASE_PATH with '~/' to hide absolute paths in error output and logs. Non-string values are returned unchanged.
Usage (internal):
rmbasepath('/var/www/html/calendula/api/sys/db.php')
// Returns: ~/api/sys/db.php
Parameters
- $r : mixed
-
The path or value to process.
Return values
mixed —The path with BASE_PATH replaced by '~/', or original value if not a string.
excClean()
Clean and format a stack trace entry for JSON output.
excClean(mixed $e) : mixed
Extracts the most relevant information from a trace entry and obscures absolute paths for security. Produces a compact, debuggable format.
Processing:
- Returns original entry if no file information (incomplete trace)
- Formats as: "~/path/to/file.php:123"
- Includes function/class information
- Sanitizes argument paths
Output format:
[
"~/api/sys/db.php:156" => [
"fun" => "Model::save",
"args" => [ "~/api/claz/User.php" ]
]
]
Parameters
- $e : mixed
-
A trace entry from Exception::getTrace().
Return values
mixed —The cleaned trace entry, or original if no file info.
final_json()
Sends a final JSON response and terminates the request.
final_json(array<string|int, mixed>|object $out) : never
This is the standardized output function for the phpEZ API. It ensures only one JSON response is sent, appends request processing time, and halts execution.
If called multiple times, subsequent calls will dump to output with "FATAL:" prefix to indicate a logic error.
The response format is:
{
"success": true,
"data": {...},
"x-time-ms": 42.5
}
Parameters
- $out : array<string|int, mixed>|object
-
The response data to encode and send as JSON. Will have 'success' and 'x-time-ms' fields added by callers.
Return values
never —This function always terminates script execution.
require_blank_ctx()
Load a PHP file in a clean context with access to the App instance.
require_blank_ctx(string $path, App $APP) : void
Used internally to load route definition files. Each loaded file receives the App instance as $APP, allowing route registration via closures.
This pattern avoids polluting the global namespace while keeping route definitions in separate files for organization.
Parameters
- $path : string
-
Absolute path to the PHP file to include.
- $APP : App
-
The application instance for route registration.
Tags
html()
Helper function to create a StringHTMLContent response.
html(string $html) : StringHTMLContent
Parameters
- $html : string
-
The HTML content to send in the response.
Return values
StringHTMLContent —A custom response object with the given HTML.
redirect()
Helper function to create a Redirect response.
redirect(string $url[, int $statusCode = 302 ]) : Redirect
Parameters
- $url : string
-
The URL to redirect to.
- $statusCode : int = 302
-
The HTTP status code for the redirect (default 302).
Return values
Redirect —A custom response object that performs the redirect.