phpEZ v0.1.3

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.
App
Central API application router and orchestrator.

Enums

HTTP
HTTP request method enum.
HTTPCode
HTTP response status codes enum.

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.

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
example
// In api/root/user.php:
$APP->get('/user/{id:i}', function(int $id) { ... });
On this page

Search results