PHP Class yii\web\CookieCollection

For more details and usage information on CookieCollection, see the guide article on handling cookies.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Object, implements IteratorAggregate, implements ArrayAccess, implements Countable
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$readOnly whether this collection is read only.

Méthodes publiques

Méthode Description
__construct ( array $cookies = [], array $config = [] ) Constructor.
add ( Cookie $cookie ) Adds a cookie to the collection.
count ( ) : integer Returns the number of cookies in the collection.
fromArray ( array $array ) Populates the cookie collection from an array.
get ( string $name ) : Cookie Returns the cookie with the specified name.
getCount ( ) : integer Returns the number of cookies in the collection.
getIterator ( ) : ArrayIterator Returns an iterator for traversing the cookies in the collection.
getValue ( string $name, mixed $defaultValue = null ) : mixed Returns the value of the named cookie.
has ( string $name ) : boolean Returns whether there is a cookie with the specified name.
offsetExists ( string $name ) : boolean Returns whether there is a cookie with the specified name.
offsetGet ( string $name ) : Cookie Returns the cookie with the specified name.
offsetSet ( string $name, Cookie $cookie ) Adds the cookie to the collection.
offsetUnset ( string $name ) Removes the named cookie.
remove ( Cookie | string $cookie, boolean $removeFromBrowser = true ) Removes a cookie.
removeAll ( ) Removes all cookies.
toArray ( ) : array Returns the collection as a PHP array.

Method Details

__construct() public méthode

Constructor.
public __construct ( array $cookies = [], array $config = [] )
$cookies array the cookies that this collection initially contains. This should be an array of name-value pairs.
$config array name-value pairs that will be used to initialize the object properties

add() public méthode

If there is already a cookie with the same name in the collection, it will be removed first.
public add ( Cookie $cookie )
$cookie Cookie the cookie to be added

count() public méthode

This method is required by the SPL Countable interface. It will be implicitly called when you use count($collection).
public count ( ) : integer
Résultat integer the number of cookies in the collection.

fromArray() public méthode

Populates the cookie collection from an array.
Since: 2.0.3
public fromArray ( array $array )
$array array the cookies to populate from

get() public méthode

Returns the cookie with the specified name.
See also: getValue()
public get ( string $name ) : Cookie
$name string the cookie name
Résultat Cookie the cookie with the specified name. Null if the named cookie does not exist.

getCount() public méthode

Returns the number of cookies in the collection.
public getCount ( ) : integer
Résultat integer the number of cookies in the collection.

getIterator() public méthode

This method is required by the SPL interface [[\IteratorAggregate]]. It will be implicitly called when you use foreach to traverse the collection.
public getIterator ( ) : ArrayIterator
Résultat ArrayIterator an iterator for traversing the cookies in the collection.

getValue() public méthode

Returns the value of the named cookie.
See also: get()
public getValue ( string $name, mixed $defaultValue = null ) : mixed
$name string the cookie name
$defaultValue mixed the value that should be returned when the named cookie does not exist.
Résultat mixed the value of the named cookie.

has() public méthode

Note that if a cookie is marked for deletion from browser, this method will return false.
See also: remove()
public has ( string $name ) : boolean
$name string the cookie name
Résultat boolean whether the named cookie exists

offsetExists() public méthode

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like isset($collection[$name]).
public offsetExists ( string $name ) : boolean
$name string the cookie name
Résultat boolean whether the named cookie exists

offsetGet() public méthode

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like $cookie = $collection[$name];. This is equivalent to CookieCollection::get.
public offsetGet ( string $name ) : Cookie
$name string the cookie name
Résultat Cookie the cookie with the specified name, null if the named cookie does not exist.

offsetSet() public méthode

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like $collection[$name] = $cookie;. This is equivalent to CookieCollection::add.
public offsetSet ( string $name, Cookie $cookie )
$name string the cookie name
$cookie Cookie the cookie to be added

offsetUnset() public méthode

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like unset($collection[$name]). This is equivalent to CookieCollection::remove.
public offsetUnset ( string $name )
$name string the cookie name

remove() public méthode

If $removeFromBrowser is true, the cookie will be removed from the browser. In this case, a cookie with outdated expiry will be added to the collection.
public remove ( Cookie | string $cookie, boolean $removeFromBrowser = true )
$cookie Cookie | string the cookie object or the name of the cookie to be removed.
$removeFromBrowser boolean whether to remove the cookie from browser

removeAll() public méthode

Removes all cookies.
public removeAll ( )

toArray() public méthode

Returns the collection as a PHP array.
public toArray ( ) : array
Résultat array the array representation of the collection. The array keys are cookie names, and the array values are the corresponding cookie objects.

Property Details

$readOnly public_oe property

whether this collection is read only.
public $readOnly