Yii Framework v1.1.10 绫诲弬鑰

CFilterChain

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浠h〃琚簲鐢ㄥ埌涓涓姩浣滅殑杩囨护鍣ㄥ垪琛ㄣ

CFilterChain渚濋潬run()杩愯杩囨护鍣ㄥ垪琛

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
action CAction 閫氳繃杩欎釜娴佺▼杩囨护鐨勫姩浣溿 CFilterChain
controller CController 杩愯杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆 CFilterChain
count integer 杩斿洖鍒楄〃鐨勯」鐩暟銆 CList
filterIndex integer 褰撹皟鐢run()鏃惰杩愯鐨勮繃婊ゅ櫒绱㈠紩銆 CFilterChain
iterator Iterator 杩斿洖閬嶅巻杩欎釜椤圭洰鍒楄〃鐨勮凯浠e櫒銆 CList
readOnly boolean 杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负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() 灏嗚凯浠e櫒涓殑鏁版嵁澶嶅埗鍒板垪琛ㄣ CList
count() 杩斿洖鍒楄〃鐨勯」鐩暟銆 CList
create() CFilterChain宸ュ巶鏂规硶銆 CFilterChain
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getCount() 杩斿洖鍒楄〃鐨勯」鐩暟銆 CList
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIterator() 杩斿洖閬嶅巻杩欎釜椤圭洰鍒楄〃鐨勮凯浠e櫒銆 CList
getReadOnly() 杩斿洖杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆 CList
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
indexOf() CList
insertAt() 灏嗛」鐩彃鍏ュ埌鎸囧畾鐨勪綅缃 CFilterChain
itemAt() 杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 CList
mergeWith() 灏嗚凯浠e櫒鐨勬暟鎹暣鍚堝埌map CList
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)
$controller CController 杩愯杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆
$action CAction 鍦ㄦ祦绋嬩腑琚繃婊ょ殑鍔ㄤ綔銆
婧愮爜锛 framework/web/filters/CFilterChain.php#43 (鏄剧ず)
public function __construct($controller,$action)
{
    
$this->controller=$controller;
    
$this->action=$action;
}

鏋勯犳柟娉曘

create() 鏂规硶
public static CFilterChain create(CController $controller, CAction $action, array $filters)
$controller CController 杩愯杩欎釜鍔ㄤ綔鐨勬帶鍒跺櫒銆
$action CAction 鍦ㄦ祦绋嬩腑琚繃婊ょ殑鍔ㄤ綔銆
$filters array 搴旂敤鍒拌繖涓姩浣滅殑杩囨护鍣ㄥ垪琛ㄣ
{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);
        }
        else if(
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宸ュ巶鏂规硶銆 杩欎釜鏂规硶鍒涘缓涓涓狢FilterChain瀹炰緥銆

insertAt() 鏂规硶
public void insertAt(integer $index, mixed $item)
$index integer 鎸囧畾鐨勪綅缃
$item mixed 鏂扮殑椤圭洰銆
婧愮爜锛 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.'));
}

灏嗛」鐩彃鍏ュ埌鎸囧畾鐨勪綅缃 杩欎釜鏂规硶閲嶅啓鐖剁被鏂规硶锛 瀹炵幇浜嗗湪娣诲姞杩囩▼涓綔 涓浜涢澶栫殑妫鏌ャ傜壒鍒槸锛 鍙湁瀹炵幇IFilter鎵嶄細琚坊鍔犲埌杩欎釜鍒楄〃銆

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);
}

杩愯鍦filterIndex绱㈠紩鐨勮繃婊ゅ櫒銆 褰撹皟鐢ㄨ繖涓柟娉曚箣鍚庯紝filterIndex浼氳嚜鍔ㄥ姞1銆 杩欎釜鏂规硶閫氬父鍦ㄨ繃婊ゅ櫒閲岄潰璋冪敤锛 鎵浠ヨ繃婊ょ殑杩囩▼鑳藉缁х画杩涜锛屽姩浣滀篃鍙互鎵ц涓嬪幓銆

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.