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_LAX

SAMESITE_STRICT

SAMESITE_NONE

Properties

static private bool $report_errors
static private $default_samesite

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

Methods

static Config_ForClass
config()

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

mixed
uninherited(string $name)

Gets the uninherited value for the given config option

static Cookie_Backend
get_inst()

Fetch the current instance of the cookie backend.

static 
set(string $name, mixed $value, float $expiry = 90, string $path = null, string $domain = null, bool $secure = false, bool $httpOnly = true)

Set a cookie variable.

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

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

static array
get_all(bool $includeUnsent = true)

Get all the cookies.

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

No description

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, mixed $value, float $expiry = 90, string $path = null, string $domain = null, bool $secure = false, bool $httpOnly = true)

Set a cookie variable.

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

Parameters

string $name
mixed $value
float $expiry
string $path
string $domain
bool $secure
bool $httpOnly

See http://php.net/set_session

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

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

Parameters

string $name
bool $includeUnsent

Return Value

null|string

static array get_all(bool $includeUnsent = true)

Get all the cookies.

Parameters

bool $includeUnsent

Return Value

array

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

Parameters

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

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

if the value is not "Strict", "Lax", or "None".