exceptions.php
Table of Contents
Classes
- HTTPException
- Base exception class for HTTP API errors.
- NotFoundException
- Exception for missing resources (HTTP 404).
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.
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.