PHP Class Cookie

Mostrar archivo Open project: symphonycms/symphony-2 Class Usage Examples

Public Methods

Method Description
__construct ( string $index, integer $timeout, string $path = '/', string $domain = null, boolean $httpOnly = true ) Constructor for the Cookie class intialises all class variables with the given parameters. Most of the parameters map to PHP's setcookie function. It creates a new Session object via the $this->__init()
expire ( ) Expires the current $_SESSION by unsetting the Symphony namespace ($this->_index). If the $_SESSION is empty, the function will destroy the entire $_SESSION
get ( string $name = null ) : string | null Accessor function for properties in the $_SESSION array
set ( string $name, string $value ) A basic setter, which will set a value to a given property in the $_SESSION array, stored in the key of $this->_index

Private Methods

Method Description
__init ( ) : Session Initialises a new Session instance using this cookie's params

Method Details

__construct() public method

Constructor for the Cookie class intialises all class variables with the given parameters. Most of the parameters map to PHP's setcookie function. It creates a new Session object via the $this->__init()
public __construct ( string $index, integer $timeout, string $path = '/', string $domain = null, boolean $httpOnly = true )
$index string The prefix to used to namespace all Symphony cookies
$timeout integer The Time to Live for a cookie, by default this is zero, meaning the cookie never expires
$path string The path the cookie is valid for on the domain
$domain string The domain this cookie is valid for
$httpOnly boolean Whether this cookie can be read by Javascript. By default the cookie cannot be read by Javascript

expire() public method

Expires the current $_SESSION by unsetting the Symphony namespace ($this->_index). If the $_SESSION is empty, the function will destroy the entire $_SESSION
public expire ( )

get() public method

Accessor function for properties in the $_SESSION array
public get ( string $name = null ) : string | null
$name string The name of the property to retrieve (optional)
return string | null The value of the property, or null if it does not exist. If no `$name` is provided, return the entire Cookie.

set() public method

A basic setter, which will set a value to a given property in the $_SESSION array, stored in the key of $this->_index
public set ( string $name, string $value )
$name string The name of the property
$value string The value of the property