final class Helpers

Helper functions for HTTP requests, responses and headers.

Methods

static string
formatDate(string|int|DateTimeInterface $time)

Formats a date and time in the HTTP date format (RFC 7231), e.g. 'Mon, 23 Jan 1978 10:00:00 GMT'.

static int|null
expirationToSeconds(string|int|DateTimeInterface|null $expire)

Converts an expiration value to the number of seconds from now (may be negative for the past).

static array
parseQualityList(string $header)

Parses an HTTP quality-value list such as the Accept, Accept-Language or Accept-Encoding header into tokens mapped to their q-factor, ordered by descending preference. Tokens are lowercased and those explicitly rejected with q=0 are omitted.

static bool
ipMatch(string $ip, string $mask)

Checks whether an IP address falls within a CIDR block (e.g. '192.168.1.0/24').

Details

at line 26
static string formatDate(string|int|DateTimeInterface $time)

Formats a date and time in the HTTP date format (RFC 7231), e.g. 'Mon, 23 Jan 1978 10:00:00 GMT'.

Parameters

string|int|DateTimeInterface $time

Return Value

string

at line 42
static int|null expirationToSeconds(string|int|DateTimeInterface|null $expire)

Converts an expiration value to the number of seconds from now (may be negative for the past).

An integer or a string representing an integer is taken directly as the number of seconds; a DateTimeInterface or any other textual string (e.g. '20 minutes', '2024-01-01') is treated as an absolute time. Returns null for null (no value); an empty string is rejected as it is never meaningful. A number that looks like an absolute UNIX timestamp is deprecated (pass a DateTimeInterface instead).

Parameters

string|int|DateTimeInterface|null $expire

Return Value

int|null

Exceptions

InvalidArgumentException
Exception

at line 73
static array parseQualityList(string $header)

Parses an HTTP quality-value list such as the Accept, Accept-Language or Accept-Encoding header into tokens mapped to their q-factor, ordered by descending preference. Tokens are lowercased and those explicitly rejected with q=0 are omitted.

Parameters

string $header

Return Value

array

e.g. ['cs-cz' => 1.0, 'en' => 0.8]

at line 103
static bool ipMatch(string $ip, string $mask)

Checks whether an IP address falls within a CIDR block (e.g. '192.168.1.0/24').

Parameters

string $ip
string $mask

Return Value

bool

Traits

StaticClass