http.php
Table of Contents
Classes
- Get
- Query parameter accessor for GET requests.
- Post
- Body parameter accessor for POST requests.
- BoolGet
- Boolean query parameter accessor for GET requests.
- Api
- Represents a single API endpoint with smart request handling.
- JSONDateTime
- DateTime serializer for JSON responses.
- CustomResponse
- Base class for custom response types with specific Content-Type handling.
- StringHTMLContent
- Base class for custom response types with specific Content-Type handling.
- Redirect
- Base class for custom response types with specific Content-Type handling.
- App
- Central API application router and orchestrator.
Enums
Functions
- 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.
Functions
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.