CFilterChain

优质
小牛编辑
125浏览
2023-12-01
所有包 | 属性 | 方法
system.web.filters
继承class CFilterChain » CList » CComponent
实现Countable, ArrayAccess, Traversable, IteratorAggregate
源自1.0
版本$Id: CFilterChain.php 3204 2011-05-05 21:36:32Z alexander.makarow $
源码framework/web/filters/CFilterChain.php
CFilterChain代表被应用到一个动作的过滤器列表。

CFilterChain依靠run()运行过滤器列表

公共属性

隐藏继承属性

属性类型描述定义在
actionCAction通过这个流程过滤的动作。CFilterChain
controllerCController运行这个动作的控制器。CFilterChain
countinteger返回列表的项目数。CList
filterIndexinteger当调用run()时要运行的过滤器索引。CFilterChain
iteratorIterator返回遍历这个项目列表的迭代器。CList
readOnlyboolean返回值说明这个列表是否为只读。默认为false。CList

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造方法。CFilterChain
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
add()在列表尾部添加一个项目。CList
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
clear()删除列表中所有项目。CList
contains()CList
copyFrom()将迭代器中的数据复制到列表。CList
count()返回列表的项目数。CList
create()CFilterChain工厂方法。CFilterChain
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getCount()返回列表的项目数。CList
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getIterator()返回遍历这个项目列表的迭代器。CList
getReadOnly()返回返回值说明这个列表是否为只读。默认为false。CList
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
indexOf()CList
insertAt()将项目插入到指定的位置。CFilterChain
itemAt()返回指定位置的项目。CList
mergeWith()将迭代器的数据整合到mapCList
offsetExists()返回值说明列表中是否包含这个项目。CList
offsetGet()返回指定位置的项目。CList
offsetSet()在指定位置插入项目。CList
offsetUnset()删除指定位置的项目。CList
raiseEvent()发起一个事件。CComponent
remove()从列表中删除一个项目。CList
removeAt()删除指定位置的项目。CList
run()运行在filterIndex索引的过滤器。CFilterChain
toArray()CList

受保护方法

隐藏继承方法

方法描述定义在
setReadOnly()设置设置这个列表是否为只读CList

属性详细

action 属性 public CAction $action;

通过这个流程过滤的动作。

controller 属性 public CController $controller;

运行这个动作的控制器。

filterIndex 属性 public integer $filterIndex;

当调用run()时要运行的过滤器索引。

方法详细

__construct() 方法
public void __construct(CController $controller, CAction $action)
$controllerCController运行这个动作的控制器。
$actionCAction在流程中被过滤的动作。
源码: framework/web/filters/CFilterChain.php#43 (显示) publicfunction__construct($controller,$action)
{
$this->controller=$controller;
$this->action=$action;
}

构造方法。

create() 方法
public static CFilterChain create(CController $controller, CAction $action, array $filters)
$controllerCController运行这个动作的控制器。
$actionCAction在流程中被过滤的动作。
$filtersarray应用到这个动作的过滤器列表。
{return}CFilterChain
源码: framework/web/filters/CFilterChain.php#57 (显示) publicstaticfunctioncreate($controller,$action,$filters)
{
$chain=newCFilterChain($controller,$action);

$actionID=$action->getId();
foreach($filtersas$filter)
{
if(is_string($filter))//filterName[+|-action1action2]
{
if(($pos=strpos($filter,'+'))!==false||($pos=strpos($filter,'-'))!==false)
{
$matched=preg_match("/b{$actionID}b/i",substr($filter,$pos+1))>0;
if(($filter[$pos]==='+')===$matched)
$filter=CInlineFilter::create($controller,trim(substr($filter,0,$pos)));
}
else
$filter=CInlineFilter::create($controller,$filter);
}
elseif(is_array($filter))//array('path.to.class[+|-action1,action2]','param1'=>'value1',...)
{
if(!isset($filter[0]))
thrownewCException(Yii::t('yii','Thefirstelementinafilterconfigurationmustbethefilterclass.'));
$filterClass=$filter[0];
unset($filter[0]);
if(($pos=strpos($filterClass,'+'))!==false||($pos=strpos($filterClass,'-'))!==false)
{
$matched=preg_match("/b{$actionID}b/i",substr($filterClass,$pos+1))>0;
if(($filterClass[$pos]==='+')===$matched)
$filterClass=trim(substr($filterClass,0,$pos));
else
continue;
}
$filter['class']=$filterClass;
$filter=Yii::createComponent($filter);
}

if(is_object($filter))
{
$filter->init();
$chain->add($filter);
}
}
return$chain;
}

CFilterChain工厂方法。 这个方法创建一个CFilterChain实例。

insertAt() 方法
public void insertAt(integer $index, mixed $item)
$indexinteger指定的位置。
$itemmixed新的项目。
源码: framework/web/filters/CFilterChain.php#111 (显示) publicfunctioninsertAt($index,$item)
{
if($iteminstanceofIFilter)
parent::insertAt($index,$item);
else
thrownewCException(Yii::t('yii','CFilterChaincanonlytakeobjectsimplementingtheIFilterinterface.'));
}

将项目插入到指定的位置。 这个方法重写父类方法, 实现了在添加过程中作 一些额外的检查。特别是, 只有实现IFilter才会被添加到这个列表。

run() 方法
public void run()
源码: framework/web/filters/CFilterChain.php#125 (显示) publicfunctionrun()
{
if($this->offsetExists($this->filterIndex))
{
$filter=$this->itemAt($this->filterIndex++);
Yii::trace('Runningfilter'.($filterinstanceofCInlineFilter?get_class($this->controller).'.filter'.$filter->name.'()':get_class($filter).'.filter()'),'system.web.filters.CFilterChain');
$filter->filter($this);
}
else
$this->controller->runAction($this->action);
}

运行在filterIndex索引的过滤器。 当调用这个方法之后,filterIndex会自动加1。 这个方法通常在过滤器里面调用, 所以过滤的过程能够继续进行,动作也可以执行下去。