class CookieJar implements QueueingFactory

Traits

Constants

protected QUEUE_CONTEXT_KEY

Context key for the queued cookies.

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected string $path

The default path (if specified).

protected string|null $domain

The default domain (if specified).

protected bool|null $secure

The default secure setting (defaults to null).

protected string|null $sameSite

The default SameSite option (defaults to lax).

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

bool
has(UnitEnum|string $key)

Determine if a cookie exists in the current request.

string|array|null
get(UnitEnum|string $key, string|array|null $default = null)

Get a cookie value from the current request.

Cookie
make(UnitEnum|string $name, string|null $value, int $minutes = 0, string|null $path = null, string|null $domain = null, bool|null $secure = null, bool $httpOnly = true, bool $raw = false, string|null $sameSite = null)

Create a new cookie instance.

Cookie
forever(UnitEnum|string $name, string $value, string|null $path = null, string|null $domain = null, bool|null $secure = null, bool $httpOnly = true, bool $raw = false, string|null $sameSite = null)

Create a cookie that lasts "forever" (400 days).

Cookie
forget(UnitEnum|string $name, string|null $path = null, string|null $domain = null)

Expire the given cookie.

bool
hasQueued(UnitEnum|string $key, string|null $path = null)

Determine if a cookie has been queued.

mixed
queued(UnitEnum|string $key, mixed $default = null, string|null $path = null)

Get a queued cookie instance.

void
queue(mixed ...$parameters)

Queue a cookie to send with the next response.

void
expire(UnitEnum|string $name, string|null $path = null, string|null $domain = null)

Queue a cookie to expire with the next response.

void
unqueue(UnitEnum|string $name, string|null $path = null)

Remove a cookie from the queue.

array
getPathAndDomain(string|null $path, string|null $domain, bool|null $secure = null, string|null $sameSite = null)

Get the path and domain, or the default values.

setDefaultPathAndDomain(string $path, string|null $domain, bool|null $secure = false, string|null $sameSite = null)

Set the default path and domain for the jar.

array
getQueuedCookies()

Get the cookies which have been queued for the next request.

flushQueuedCookies()

Flush the cookies which have been queued for the next request.

array
getQueuedCookiesRaw()

Get the raw queued cookies array (keyed by name and path).

void
setQueuedCookies(array $cookies)

Set the queued cookies in the coroutine context.

static void
flushState()

Flush all static state.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 51
bool has(UnitEnum|string $key)

Determine if a cookie exists in the current request.

Parameters

UnitEnum|string $key

Return Value

bool

at line 59
string|array|null get(UnitEnum|string $key, string|array|null $default = null)

Get a cookie value from the current request.

Parameters

UnitEnum|string $key
string|array|null $default

Return Value

string|array|null

at line 76
Cookie make(UnitEnum|string $name, string|null $value, int $minutes = 0, string|null $path = null, string|null $domain = null, bool|null $secure = null, bool $httpOnly = true, bool $raw = false, string|null $sameSite = null)

Create a new cookie instance.

Parameters

UnitEnum|string $name
string|null $value
int $minutes
string|null $path
string|null $domain
bool|null $secure
bool $httpOnly
bool $raw
string|null $sameSite

Return Value

Cookie

at line 90
Cookie forever(UnitEnum|string $name, string $value, string|null $path = null, string|null $domain = null, bool|null $secure = null, bool $httpOnly = true, bool $raw = false, string|null $sameSite = null)

Create a cookie that lasts "forever" (400 days).

Parameters

UnitEnum|string $name
string $value
string|null $path
string|null $domain
bool|null $secure
bool $httpOnly
bool $raw
string|null $sameSite

Return Value

Cookie

at line 98
Cookie forget(UnitEnum|string $name, string|null $path = null, string|null $domain = null)

Expire the given cookie.

Parameters

UnitEnum|string $name
string|null $path
string|null $domain

Return Value

Cookie

at line 106
bool hasQueued(UnitEnum|string $key, string|null $path = null)

Determine if a cookie has been queued.

Parameters

UnitEnum|string $key
string|null $path

Return Value

bool

at line 116
mixed queued(UnitEnum|string $key, mixed $default = null, string|null $path = null)

Get a queued cookie instance.

Parameters

UnitEnum|string $key
mixed $default
string|null $path

Return Value

mixed

at line 131
void queue(mixed ...$parameters)

Queue a cookie to send with the next response.

Parameters

mixed ...$parameters

Return Value

void

at line 153
void expire(UnitEnum|string $name, string|null $path = null, string|null $domain = null)

Queue a cookie to expire with the next response.

Parameters

UnitEnum|string $name
string|null $path
string|null $domain

Return Value

void

at line 161
void unqueue(UnitEnum|string $name, string|null $path = null)

Remove a cookie from the queue.

Parameters

UnitEnum|string $name
string|null $path

Return Value

void

at line 186
protected array getPathAndDomain(string|null $path, string|null $domain, bool|null $secure = null, string|null $sameSite = null)

Get the path and domain, or the default values.

Parameters

string|null $path
string|null $domain
bool|null $secure
string|null $sameSite

Return Value

array

at line 198
CookieJar setDefaultPathAndDomain(string $path, string|null $domain, bool|null $secure = false, string|null $sameSite = null)

Set the default path and domain for the jar.

Boot-only. The defaults persist on the worker-lifetime singleton; per-request mutation races across coroutines and affects every subsequent request.

Parameters

string $path
string|null $domain
bool|null $secure
string|null $sameSite

Return Value

CookieJar

at line 210
array getQueuedCookies()

Get the cookies which have been queued for the next request.

Return Value

array

at line 218
CookieJar flushQueuedCookies()

Flush the cookies which have been queued for the next request.

Return Value

CookieJar

at line 228
protected array getQueuedCookiesRaw()

Get the raw queued cookies array (keyed by name and path).

Return Value

array

at line 236
protected void setQueuedCookies(array $cookies)

Set the queued cookies in the coroutine context.

Parameters

array $cookies

Return Value

void

at line 244
static void flushState()

Flush all static state.

Return Value

void