Header
Reads request headers and manages outgoing response headers and HTTP status codes.
Centralized HTTP headers
Use Core\Header for reading request headers and setting outgoing headers. Avoid direct calls
to
header() and http_response_code() in application code when the Core API is
available.
Example
$header = Registry::get(Header::class);
$userAgent = $header->getRequest('User-Agent');
Public API Reference
Core\Header
Class & Registry
Class:
Core\Header
Extends:
Core\Header\Base
use Core\Header;
use Core\Registry;
$header = Registry::get(Header::class);
| Method | Description |
|---|---|
init():void |
Initializes the header controller and sets the APPNETOS base URL and context URL as response headers. |
get(string|null $name = null, bool $assoc = false):array|string|null |
Returns a response header by name, or all response headers if no name is specified. Optionally returns parsed header name and value pairs. |
getAll(bool $assoc = false):array |
Returns all outgoing response headers as strings or parsed name and value pairs. |
getAssoc():array |
Returns all outgoing response headers as an associative array with header names as keys and their values as entries. |
set(string $header, bool $replace = true):void |
Sets an outgoing HTTP response header, optionally replacing an existing header with the same name. |
add(string $header, bool $replace = true):void |
Adds an outgoing HTTP response header using the same behavior as set().
|
remove(string|null $name = null):void |
Removes the specified outgoing response header, or all response headers when no name is provided. |
getStatusMessage(int $status):string|null |
Returns the standard HTTP status message for a supported status code, or
null if the code is unknown.
|
setStatusCode(int|null $status = null):void |
Sets the HTTP response status code, defaulting to 200, and validates it against the supported APPNETOS status codes. |
getRequest(string|null $name = null):array|string|null |
Returns an incoming HTTP request header using case-insensitive name matching, or all normalized request headers when no name is specified. |