class Cookie (View source)

A set of static methods for manipulating cookies.

Traits

Provides extensions to this object to integrate it with standard config API methods.

Constants

SAMESITE_STRICT

SAMESITE_LAX

SAMESITE_NONE

Config options

report_errors bool
default_samesite string

Must be "Strict", "Lax", or "None"

Properties

Methods

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public static 
get_inst()

Fetch the current instance of the cookie backend.

public static 
set(string $name, string|false $value, int $expiry = 90, string|null $path = null, string|null $domain = null, bool $secure = false, bool $httpOnly = true, string $sameSite = '')

Set a cookie variable.

public static 
string|null
get(string $name, bool $includeUnsent = true)

Get the cookie value by name. Returns null if not set.

public static 
array
get_all(bool $includeUnsent = true)

Get all the cookies.

public static 
void
force_expiry(string $name, string|null $path = null, string|null $domain = null, bool $secure = false, bool $httpOnly = true, string $sameSite = '')

Force the expiry of a cookie by name

public static 
string
getDefaultSameSite()

Get the default value for the "samesite" cookie attribute.

public static 
void
validateSameSite(string $sameSite)

Validate if the samesite value for a cookie is valid for the current request.

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

static Cookie_Backend get_inst()

Fetch the current instance of the cookie backend.

Return Value

Cookie_Backend

static set(string $name, string|false $value, int $expiry = 90, string|null $path = null, string|null $domain = null, bool $secure = false, bool $httpOnly = true, string $sameSite = '')

Set a cookie variable.

Expiry time is set in days, and defaults to 90.

See http://php.net/set_session

Parameters

string $name
string|false $value
int $expiry
string|null $path
string|null $domain
bool $secure
bool $httpOnly
string $sameSite

static string|null get(string $name, bool $includeUnsent = true)

Get the cookie value by name. Returns null if not set.

Parameters

string $name
bool $includeUnsent

Return Value

string|null

static array get_all(bool $includeUnsent = true)

Get all the cookies.

Parameters

bool $includeUnsent

Return Value

array

static void force_expiry(string $name, string|null $path = null, string|null $domain = null, bool $secure = false, bool $httpOnly = true, string $sameSite = '')

Force the expiry of a cookie by name

Parameters

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

Return Value

void

static string getDefaultSameSite()

Get the default value for the "samesite" cookie attribute.

Return Value

string

static void validateSameSite(string $sameSite)

Validate if the samesite value for a cookie is valid for the current request.

Logs a warning if the samesite value is "None" for a non-https request.

Parameters

string $sameSite

Return Value

void

Exceptions

LogicException