Skip to content

Headers

HTTP headers are key-value pairs sent with requests and responses. Centum provides classes to represent and manage headers in a type-safe way.

Centum\Http\Header

Represents a single HTTP header.

Centum\Http\Header(
    string $name,
    string $value
);

Centum\Http\Header implements Centum\Interfaces\Http\HeaderInterface.

Centum\Http\Headers

Represents a collection of HTTP headers.

Centum\Http\Headers implements Centum\Interfaces\Http\HeadersInterface.

Example

use Centum\Http\Header;
use Centum\Http\Headers;

$headers = new Headers(
    [
        new Header("Content-Type", "application/json"),
        new Header("Cache-Control", "no-cache"),
    ]
);

Headers Factory

You can obtain a Headers object populated from global variables using HeadersFactory:

use Centum\Http\HeadersFactory;

$headersFactory = new HeadersFactory();

$headers = $headersFactory->createFromGlobals();