Request
The Request class acts as the central nervous system for HTTP data. It normalizes inputs from $_GET, $_POST, and JSON bodies into a unified API, while providing utilities for state management and smart redirection.
Data Containers
Parameters
Unified access to input data.
-
static ArrayObject $paramsMerged data from GET, POST, or JSON body. -
static mixed $dataRaw parsed body data (e.g., decoded JSON array). -
static ArrayObject $dynamicParamsCaptured route parameters (e.g., from[id],[...other]).
Wire Detection
How the request reached this route.
-
static bool $isRpcThe request is app.rpc(...)call for an exposed function. -
static bool $isNavigationThe request is an SPA navigation rather than a full page load. -
static bool $isWireAny PulsePoint wire request.Request::redirect()uses this to choose between aLocationheader and theX-PP-Redirectheader family.
Request Flags & Context
Method Flags
- $isGet
- $isPost
- $isPut
- $isDelete
- $isPatch
- $isHead
- $isOptions
Request Type
$isAjax- XHR/Fetch request$isWire- PulsePoint Wire request$isXFileRequest- File fetch context
Context Info
$method- (string) GET, POST...$protocol- http:// or https://$remoteAddr- IP Address$requestedWith- Header value
URL & Path Properties
| Property | Description |
|---|---|
| $pathname | The request path (e.g., /dashboard/user). |
| $uri | Full URI including query strings. |
| $documentUrl | Full URL including protocol and domain. |
| $referer | The HTTP referer URL. |
Utility Methods
static redirect(string $url, bool $replace = true, int $code = 0): void
Smart redirection. If the request is Wire or Ajax, it returns a control string redirect_7F834=... instead of a header, allowing the frontend framework to handle the navigation without a hard reload.
static getBearerToken(): ?string
Parses the Authorization header and extracts the Bearer token. Returns null if missing.
static handlePreflight(): void
Checks if the method is OPTIONS. If so, sends 200 OK and exits immediately. Useful for API endpoints.
static getDecodedUrl(string $uri): string
Parses a URI and returns the path with the query string decoded.
Usage Examples
1. Basic Initialization & Param Access
<?php
use PP\Request;
// Accessing params (works for GET, POST, or JSON body)
$userId = Request::$params->userId ?? null;
if (Request::$isPost) {
// Handle form submission
}
?>
2. Branching on how the request arrived
A route file runs for a full page load, an SPA navigation and an RPC call alike. The wire flags let you skip work only the first of those needs.
<?php
use PP\Request;
// Expensive one-off setup that an RPC round trip does not need
if (!Request::$isRpc) {
$stats = loadDashboardStats();
}
?>
Request::$params adapts to the request: on a
GET it wraps $_GET, and on a JSON body it wraps the decoded
payload — the same value you can read raw from Request::$data. An unparseable JSON body is
rejected with a 400 before your code runs.
3. API Endpoint Protection
<?php
use PP\Request;
use PP\Headers\Boom;
Request::handlePreflight(); // Handle CORS OPTIONS check
// Ensure only POST is allowed
if (!Request::$isPost) {
Boom::methodNotAllowed()->toResponse();
}
$token = Request::getBearerToken();
if (!$token) {
Boom::unauthorized()->toResponse();
}
// Process JSON Data
$data = Request::$data;
?>