CCookieCollection

优质
小牛编辑
132浏览
2023-12-01
所有包 | 属性 | 方法
system.web
继承class CCookieCollection » CMap » CComponent
实现Countable, ArrayAccess, Traversable, IteratorAggregate
源自1.0
版本$Id: CHttpRequest.php 3560 2012-02-10 14:13:00Z mdomba $
源码framework/web/CHttpRequest.php
CCookieCollection implements a collection class to store cookies.

You normally access it via CHttpRequest::getCookies().

Since CCookieCollection extends from CMap, it can be used like an associative array as follows:
$cookies[$name]=new CHttpCookie($name,$value); // sends a cookie
$value=$cookies[$name]->value; // reads a cookie value
unset($cookies[$name]);  // removes a cookie

公共属性

隐藏继承属性

属性类型描述定义在
countinteger返回map中的项目数。CMap
iteratorCMapIterator返回遍历这个列表的项目的迭代器。CMap
keysarray返回键名列表CMap
readOnlyboolean返回值说明这个列表是否为只读。默认为false。CMap
requestCHttpRequestthe request instanceCCookieCollection

受保护属性

隐藏继承属性

属性类型描述定义在
cookiesarraylist of validated cookiesCCookieCollection

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()Constructor.CCookieCollection
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
add()Adds a cookie with the specified name.CCookieCollection
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
clear()删除map中所有项目。CMap
contains()CMap
copyFrom()将迭代器中的数据复制到map。CMap
count()返回map中的项目数。CMap
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getCount()返回map中的项目数。CMap
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getIterator()返回遍历这个列表的项目的迭代器。CMap
getKeys()返回返回键名列表CMap
getReadOnly()返回返回值说明这个列表是否为只读。默认为false。CMap
getRequest()返回the request instanceCCookieCollection
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
itemAt()返回指定位置的项目。CMap
mergeArray()递归合并两个或多个数组。CMap
mergeWith()将迭代器的数据整合到map。CMap
offsetExists()返回值说明指定位置是否存在元素。CMap
offsetGet()返回值指定位置的元素。CMap
offsetSet()设置指定位置的元素。CMap
offsetUnset()删除指定位置的元素。CMap
raiseEvent()发起一个事件。CComponent
remove()Removes a cookie with the specified name.CCookieCollection
toArray()CMap

受保护方法

隐藏继承方法

方法描述定义在
addCookie()Sends a cookie.CCookieCollection
getCookies()返回list of validated cookiesCCookieCollection
removeCookie()Deletes a cookie.CCookieCollection
setReadOnly()设置设置这个列表是否为只读CMap

属性详细

cookies 属性 只读 protected array getCookies()

list of validated cookies

request 属性 只读 public CHttpRequest getRequest()

the request instance

方法详细

__construct() 方法
public void __construct(CHttpRequest $request)
$requestCHttpRequestowner of this collection.
源码: framework/web/CHttpRequest.php#962 (显示) publicfunction__construct(CHttpRequest$request)
{
$this->_request=$request;
$this->copyfrom($this->getCookies());
$this->_initialized=true;
}

Constructor.

add() 方法
public void add(mixed $name, CHttpCookie $cookie)
$namemixedCookie name.
$cookieCHttpCookieCookie object.
源码: framework/web/CHttpRequest.php#1008 (显示) publicfunctionadd($name,$cookie)
{
if($cookieinstanceofCHttpCookie)
{
$this->remove($name);
parent::add($name,$cookie);
if($this->_initialized)
$this->addCookie($cookie);
}
else
thrownewCException(Yii::t('yii','CHttpCookieCollectioncanonlyholdCHttpCookieobjects.'));
}

Adds a cookie with the specified name. This overrides the parent implementation by performing additional operations for each newly added CHttpCookie object.

addCookie() 方法
protected void addCookie(CHttpCookie $cookie)
$cookieCHttpCookiecookie to be sent
源码: framework/web/CHttpRequest.php#1042 (显示) protectedfunctionaddCookie($cookie)
{
$value=$cookie->value;
if($this->_request->enableCookieValidation)
$value=Yii::app()->getSecurityManager()->hashData(serialize($value));
if(version_compare(PHP_VERSION,'5.2.0','>='))
setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
else
setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure);
}

Sends a cookie.

getCookies() 方法
protected array getCookies()
{return}arraylist of validated cookies
源码: framework/web/CHttpRequest.php#980 (显示) protectedfunctiongetCookies()
{
$cookies=array();
if($this->_request->enableCookieValidation)
{
$sm=Yii::app()->getSecurityManager();
foreach($_COOKIEas$name=>$value)
{
if(is_string($value)&&($value=$sm->validateData($value))!==false)
$cookies[$name]=newCHttpCookie($name,@unserialize($value));
}
}
else
{
foreach($_COOKIEas$name=>$value)
$cookies[$name]=newCHttpCookie($name,$value);
}
return$cookies;
}
getRequest() 方法
public CHttpRequest getRequest()
{return}CHttpRequestthe request instance
源码: framework/web/CHttpRequest.php#972 (显示) publicfunctiongetRequest()
{
return$this->_request;
}
remove() 方法
public CHttpCookie remove(mixed $name)
$namemixedCookie name.
{return}CHttpCookieThe removed cookie object.
源码: framework/web/CHttpRequest.php#1028 (显示) publicfunctionremove($name)
{
if(($cookie=parent::remove($name))!==null)
{
if($this->_initialized)
$this->removeCookie($cookie);
}
return$cookie;
}

Removes a cookie with the specified name. This overrides the parent implementation by performing additional cleanup work when removing a CHttpCookie object.

removeCookie() 方法
protected void removeCookie(CHttpCookie $cookie)
$cookieCHttpCookiecookie to be deleted
源码: framework/web/CHttpRequest.php#1057 (显示) protectedfunctionremoveCookie($cookie)
{
if(version_compare(PHP_VERSION,'5.2.0','>='))
setcookie($cookie->name,null,0,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
else
setcookie($cookie->name,null,0,$cookie->path,$cookie->domain,$cookie->secure);
}

Deletes a cookie.