class CookieJar implements Cookie_Backend

A default backend for the setting and getting of cookies

This backend allows one to better test Cookie setting and separate cookie handling from the core

Methods

__construct(array $cookies = array())

When creating the backend we want to store the existing cookies in our "existing" array. This allows us to distinguish between cookies we received or we set ourselves (and didn't get from the browser)

set(string $name, string $value, int $expiry = 90, string $path = null, string $domain = null, boolean $secure = false, boolean $httpOnly = true)

Set a cookie

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

Get the cookie value by name

array
getAll(boolean $includeUnsent = true)

Get all the cookies

forceExpiry(string $name, string $path = null, string $domain = null, boolean $secure = false, boolean $httpOnly = true)

Force the expiry of a cookie by name

Details

at line 54
__construct(array $cookies = array())

When creating the backend we want to store the existing cookies in our "existing" array. This allows us to distinguish between cookies we received or we set ourselves (and didn't get from the browser)

Parameters

array $cookies The existing cookies to load into the cookie jar

at line 72
set(string $name, string $value, int $expiry = 90, string $path = null, string $domain = null, boolean $secure = false, boolean $httpOnly = true)

Set a cookie

Parameters

string $name The name of the cookie
string $value The value for the cookie to hold
int $expiry The number of days until expiry
string $path The path to save the cookie on (falls back to site base)
string $domain The domain to make the cookie available on
boolean $secure Can the cookie only be sent over SSL?
boolean $httpOnly Prevent the cookie being accessible by JS

at line 108
string|null get(string $name, boolean $includeUnsent = true)

Get the cookie value by name

Cookie names are normalised to work around PHP's behaviour of replacing incoming variable name . with _

Parameters

string $name The name of the cookie to get
boolean $includeUnsent Include cookies we've yet to send when fetching values

Return Value

string|null The cookie value or null if unset

at line 129
array getAll(boolean $includeUnsent = true)

Get all the cookies

Parameters

boolean $includeUnsent Include cookies we've yet to send

Return Value

array All the cookies

at line 143
forceExpiry(string $name, string $path = null, string $domain = null, boolean $secure = false, boolean $httpOnly = true)

Force the expiry of a cookie by name

Parameters

string $name The name of the cookie to expire
string $path The path to save the cookie on (falls back to site base)
string $domain The domain to make the cookie available on
boolean $secure Can the cookie only be sent over SSL?
boolean $httpOnly Prevent the cookie being accessible by JS