PHP Класс yii\web\CookieCollection

For more details and usage information on CookieCollection, see the guide article on handling cookies.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Object, implements IteratorAggregate, implements ArrayAccess, implements Countable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$readOnly whether this collection is read only.

Открытые методы

Метод Описание
__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.

Описание методов

__construct() публичный Метод

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() публичный Метод

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() публичный Метод

This method is required by the SPL Countable interface. It will be implicitly called when you use count($collection).
public count ( ) : integer
Результат integer the number of cookies in the collection.

fromArray() публичный Метод

Populates the cookie collection from an array.
С версии: 2.0.3
public fromArray ( array $array )
$array array the cookies to populate from

get() публичный Метод

Returns the cookie with the specified name.
См. также: getValue()
public get ( string $name ) : Cookie
$name string the cookie name
Результат Cookie the cookie with the specified name. Null if the named cookie does not exist.

getCount() публичный Метод

Returns the number of cookies in the collection.
public getCount ( ) : integer
Результат integer the number of cookies in the collection.

getIterator() публичный Метод

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
Результат ArrayIterator an iterator for traversing the cookies in the collection.

getValue() публичный Метод

Returns the value of the named cookie.
См. также: 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.
Результат mixed the value of the named cookie.

has() публичный Метод

Note that if a cookie is marked for deletion from browser, this method will return false.
См. также: remove()
public has ( string $name ) : boolean
$name string the cookie name
Результат boolean whether the named cookie exists

offsetExists() публичный Метод

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
Результат boolean whether the named cookie exists

offsetGet() публичный Метод

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
Результат Cookie the cookie with the specified name, null if the named cookie does not exist.

offsetSet() публичный Метод

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() публичный Метод

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() публичный Метод

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() публичный Метод

Removes all cookies.
public removeAll ( )

toArray() публичный Метод

Returns the collection as a PHP array.
public toArray ( ) : array
Результат array the array representation of the collection. The array keys are cookie names, and the array values are the corresponding cookie objects.

Описание свойств

$readOnly публичное свойство

whether this collection is read only.
public $readOnly