system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CFilterChain

system.web.filters
继承 class CFilterChain » CList » CComponent
实现 Countable, ArrayAccess, Traversable, IteratorAggregate
可用自 1.0
源码 framework/web/filters/CFilterChain.php
CFilterChain represents a list of filters being applied to an action.

CFilterChain executes the filter list by run().

公共属性

隐藏继承的属性

属性类型描述被定义在
action CAction the action being filtered by this chain. CFilterChain
controller CController the controller who executes the action. CFilterChain
count integer Returns the number of items in the list. CList
filterIndex integer the index of the filter that is to be executed when calling run(). CFilterChain
iterator Iterator Returns an iterator for traversing the items in the list. CList
readOnly boolean whether this list is read-only or not. CList

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CFilterChain
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
add() Appends an item at the end of the list. CList
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clear() Removes all items in the list. CList
contains() CList
copyFrom() Copies iterable data into the list. CList
count() Returns the number of items in the list. CList
create() CFilterChain factory method. CFilterChain
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getCount() Returns the number of items in the list. CList
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getIterator() Returns an iterator for traversing the items in the list. CList
getReadOnly() Returns whether this list is read-only or not. Defaults to false. CList
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
indexOf() CList
insertAt() Inserts an item at the specified position. CFilterChain
itemAt() Returns the item at the specified offset. CList
mergeWith() Merges iterable data into the map. CList
offsetExists() Returns whether there is an item at the specified offset. CList
offsetGet() Returns the item at the specified offset. CList
offsetSet() Sets the item at the specified offset. CList
offsetUnset() Unsets the item at the specified offset. CList
raiseEvent() Raises an event. CComponent
remove() Removes an item from the list. CList
removeAt() Removes an item at the specified position. CList
run() Executes the filter indexed at filterIndex. CFilterChain
toArray() CList

受保护的方法

隐藏继承的方法

方法描述被定义在
setReadOnly() Sets whether this list is read-only or not CList

属性详情

action 属性
public CAction $action;

the action being filtered by this chain.

controller 属性
public CController $controller;

the controller who executes the action.

filterIndex 属性
public integer $filterIndex;

the index of the filter that is to be executed when calling run().

方法详情

__construct() 方法
public void __construct(CController $controller, CAction $action)
$controller CController the controller who executes the action.
$action CAction the action being filtered by this chain.
源码: framework/web/filters/CFilterChain.php#42 (显示)
public function __construct($controller,$action)
{
    
$this->controller=$controller;
    
$this->action=$action;
}

Constructor.

create() 方法
public static CFilterChain create(CController $controller, CAction $action, array $filters)
$controller CController the controller who executes the action.
$action CAction the action being filtered by this chain.
$filters array list of filters to be applied to the action.
{return} CFilterChain
源码: framework/web/filters/CFilterChain.php#57 (显示)
public static function create($controller,$action,$filters)
{
    
$chain=new CFilterChain($controller,$action);

    
$actionID=$action->getId();
    foreach(
$filters as $filter)
    {
        if(
is_string($filter))  // filterName [+|- action1 action2]
        
{
            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]))
                throw new 
CException(Yii::t('yii','The first element in a filter configuration must be the filter class.'));
            
$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 factory method. This method creates a CFilterChain instance.

insertAt() 方法
public void insertAt(integer $index, mixed $item)
$index integer the specified position.
$item mixed new item
源码: framework/web/filters/CFilterChain.php#111 (显示)
public function insertAt($index,$item)
{
    if(
$item instanceof IFilter)
        
parent::insertAt($index,$item);
    else
        throw new 
CException(Yii::t('yii','CFilterChain can only take objects implementing the IFilter interface.'));
}

Inserts an item at the specified position. This method overrides the parent implementation by adding additional check for the item to be added. In particular, only objects implementing IFilter can be added to the list.

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

Executes the filter indexed at filterIndex. After this method is called, filterIndex will be automatically incremented by one. This method is usually invoked in filters so that the filtering process can continue and the action can be executed.