Yii Framework v1.1.10 绫诲弬鑰

CList

system.collections
缁ф壙 class CList » CComponent
瀹炵幇 IteratorAggregate, Traversable, ArrayAccess, Countable
瀛愮被 CFilterChain, CTypedList
婧愯嚜 1.0
鐗堟湰 $Id: CList.php 3430 2011-11-02 23:10:03Z alexander.makarow@gmail.com $
婧愮爜 framework/collections/CList.php
CList瀹炵幇涓涓暣鏁扮储寮曠殑闆嗗悎绫汇

浣犲彲浠ラ氳繃浣跨敤 itemAtaddinsertAtremove锛屼互鍙removeAt璁块棶锛屾坊鍔狅紝鎻掑叆锛屽垹闄ら」鐩 閫氳繃getCount锛屼綘鍙互鍙栧緱杩欎釜鍒楄〃鐨勯」鐩暟銆 濡備笅鎵绀猴紝CList涔熷彲浠ュ綋浣滀竴鑸暟缁勬潵浣跨敤锛
$list[]=$item;  //鍦ㄥ熬閮ㄦ坊鍔
$list[$index]=$item; //$index涓瀹氳鍦0鍜$list->Count涔嬮棿
unset($list[$index]); //鍒犻櫎鎸囧畾$index鐨勯」鐩
if(isset($list[$index])) //濡傛灉鍒楄〃涓瓨鍦$index鎸囧畾鐨勯」鐩
foreach($list as $index=>$item) //閬嶅巻鍒楄〃涓殑椤圭洰
$n=count($list); //杩斿洖鍒楄〃涓殑椤圭洰鏁


閫氳繃閲嶅啓insertAt()锛屼互涓removeAt()To extend CList by doing additional operations with each addition or removal 浣犲彲浠ュ湪鎷ユ湁娣诲姞/鍒犻櫎鎿嶄綔鐨勫熀纭涓婃墿灞曢澶栫殑鎿嶄綔锛堝绫诲瀷妫鏌ワ級銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
count integer 杩斿洖鍒楄〃鐨勯」鐩暟銆 CList
iterator Iterator 杩斿洖閬嶅巻杩欎釜椤圭洰鍒楄〃鐨勮凯浠e櫒銆 CList
readOnly boolean 杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆 CList

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犳柟娉曘 CList
__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
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() 灏嗛」鐩彃鍏ュ埌鎸囧畾浣嶇疆銆 CList
itemAt() 杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 CList
mergeWith() 灏嗚凯浠e櫒鐨勬暟鎹暣鍚堝埌map CList
offsetExists() 杩斿洖鍊艰鏄庡垪琛ㄤ腑鏄惁鍖呭惈杩欎釜椤圭洰銆 CList
offsetGet() 杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 CList
offsetSet() 鍦ㄦ寚瀹氫綅缃彃鍏ラ」鐩 CList
offsetUnset() 鍒犻櫎鎸囧畾浣嶇疆鐨勯」鐩 CList
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
remove() 浠庡垪琛ㄤ腑鍒犻櫎涓涓」鐩 CList
removeAt() 鍒犻櫎鎸囧畾浣嶇疆鐨勯」鐩 CList
toArray() CList

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
setReadOnly() 璁剧疆璁剧疆杩欎釜鍒楄〃鏄惁涓哄彧璇 CList

灞炴ц缁

count 灞炴 鍙
public integer getCount()

杩斿洖鍒楄〃鐨勯」鐩暟銆

iterator 灞炴 鍙
public Iterator getIterator()

杩斿洖閬嶅巻杩欎釜椤圭洰鍒楄〃鐨勮凯浠e櫒銆 姝ゆ柟娉曚负鎺ュ彛IteratorAggregate寮哄埗瑕佹眰瀹炵幇銆

readOnly 灞炴
public boolean getReadOnly()
protected void setReadOnly(boolean $value)

杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆

鏂规硶璇︾粏

__construct() 鏂规硶
public void __construct(array $data=NULL, boolean $readOnly=false)
$data array 鍒濆鍖栫殑鏁版嵁銆傞粯璁や负null锛屾剰鍛崇潃娌℃湁鍒濆鍖栥
$readOnly boolean 鏍囪瘑杩欎釜鍒楄〃鏄惁涓哄彧璇汇
婧愮爜锛 framework/collections/CList.php#61 (鏄剧ず)
public function __construct($data=null,$readOnly=false)
{
    if(
$data!==null)
        
$this->copyFrom($data);
    
$this->setReadOnly($readOnly);
}

鏋勯犳柟娉曘 鏍规嵁鏁扮粍鎴栬呰凯浠e璞″垵濮嬪寲杩欎釜鍒楄〃銆

add() 鏂规硶
public integer add(mixed $item)
$item mixed 鏂扮殑椤圭洰
{return} integer 杩斿洖鍦ㄥ姞鍏ヨ椤圭洰鐨勪粠闆跺紑濮嬬殑绱㈠紩
婧愮爜锛 framework/collections/CList.php#136 (鏄剧ず)
public function add($item)
{
    
$this->insertAt($this->_c,$item);
    return 
$this->_c-1;
}

鍦ㄥ垪琛ㄥ熬閮ㄦ坊鍔犱竴涓」鐩

clear() 鏂规硶
public void clear()
婧愮爜锛 framework/collections/CList.php#221 (鏄剧ず)
public function clear()
{
    for(
$i=$this->_c-1;$i>=0;--$i)
        
$this->removeAt($i);
}

鍒犻櫎鍒楄〃涓墍鏈夐」鐩

contains() 鏂规硶
public boolean contains(mixed $item)
$item mixed 椤圭洰瀵硅薄
{return} boolean 杩斿洖鍊艰鏄庡垪琛ㄤ腑鏄惁鍖呭惈杩欎釜椤圭洰銆
婧愮爜锛 framework/collections/CList.php#231 (鏄剧ず)
public function contains($item)
{
    return 
$this->indexOf($item)>=0;
}

copyFrom() 鏂规硶
public void copyFrom(mixed $data)
$data mixed 瑕佸鍒剁殑鏁版嵁, 鍙兘鏄暟缁勬垨鑰呯户鎵夸簬Traversable鐨勫璞°
婧愮爜锛 framework/collections/CList.php#262 (鏄剧ず)
public function copyFrom($data)
{
    if(
is_array($data) || ($data instanceof Traversable))
    {
        if(
$this->_c>0)
            
$this->clear();
        if(
$data instanceof CList)
            
$data=$data->_d;
        foreach(
$data as $item)
            
$this->add($item);
    }
    else if(
$data!==null)
        throw new 
CException(Yii::t('yii','List data must be an array or an object implementing Traversable.'));
}

灏嗚凯浠e櫒涓殑鏁版嵁澶嶅埗鍒板垪琛ㄣ 娉ㄦ剰锛屽垪琛ㄤ腑宸茬粡瀛樺湪鐨勬暟鎹細琚鍏堝垹闄ゃ

count() 鏂规硶
public integer count()
{return} integer 杩斿洖鍒楄〃鐨勯」鐩暟銆
婧愮爜锛 framework/collections/CList.php#99 (鏄剧ず)
public function count()
{
    return 
$this->getCount();
}

杩斿洖鍒楄〃鐨勯」鐩暟銆 姝ゆ柟娉曚负鎺ュ彛Countable寮哄埗瑕佹眰瀹炵幇銆

getCount() 鏂规硶
public integer getCount()
{return} integer 杩斿洖鍒楄〃鐨勯」鐩暟
婧愮爜锛 framework/collections/CList.php#108 (鏄剧ず)
public function getCount()
{
    return 
$this->_c;
}

杩斿洖鍒楄〃鐨勯」鐩暟銆

getIterator() 鏂规硶
public Iterator getIterator()
{return} Iterator 杩斿洖鐢ㄦ潵閬嶅巻鍒楄〃涓殑椤圭洰鐨勮凯浠e櫒銆
婧愮爜锛 framework/collections/CList.php#89 (鏄剧ず)
public function getIterator()
{
    return new 
CListIterator($this->_d);
}

杩斿洖閬嶅巻杩欎釜椤圭洰鍒楄〃鐨勮凯浠e櫒銆 姝ゆ柟娉曚负鎺ュ彛IteratorAggregate寮哄埗瑕佹眰瀹炵幇銆

getReadOnly() 鏂规硶
public boolean getReadOnly()
{return} boolean 杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆
婧愮爜锛 framework/collections/CList.php#71 (鏄剧ず)
public function getReadOnly()
{
    return 
$this->_r;
}

indexOf() 鏂规硶
public integer indexOf(mixed $item)
$item mixed 椤圭洰瀵硅薄
{return} integer 杩斿洖椤圭洰鍦ㄥ垪琛ㄤ腑鐨勭储寮曞硷紙鍩轰簬锛愶級锛-1琛ㄧず娌℃湁鎵惧埌銆
婧愮爜锛 framework/collections/CList.php#240 (鏄剧ず)
public function indexOf($item)
{
    if((
$index=array_search($item,$this->_d,true))!==false)
        return 
$index;
    else
        return -
1;
}

insertAt() 鏂规硶
public void insertAt(integer $index, mixed $item)
$index integer 鎸囧畾浣嶇疆銆
$item mixed 鏂扮殑椤圭洰
婧愮爜锛 framework/collections/CList.php#150 (鏄剧ず)
public function insertAt($index,$item)
{
    if(!
$this->_r)
    {
        if(
$index===$this->_c)
            
$this->_d[$this->_c++]=$item;
        else if(
$index>=&& $index<$this->_c)
        {
            
array_splice($this->_d,$index,0,array($item));
            
$this->_c++;
        }
        else
            throw new 
CException(Yii::t('yii','List index "{index}" is out of bound.',
                array(
'{index}'=>$index)));
    }
    else
        throw new 
CException(Yii::t('yii','The list is read only.'));
}

灏嗛」鐩彃鍏ュ埌鎸囧畾浣嶇疆銆 璇ヤ綅缃殑鍘熼」鐩拰 瀹冨悗闈㈢洿鍒板垪琛ㄧ粨鏉熺殑椤圭洰浼氳鍒犻櫎銆

itemAt() 鏂规硶
public mixed itemAt(integer $index)
$index integer 椤圭洰鐨勭储寮曞
{return} mixed 绱㈠紩瀵瑰簲鐨勯」鐩
婧愮爜锛 framework/collections/CList.php#120 (鏄剧ず)
public function itemAt($index)
{
    if(isset(
$this->_d[$index]))
        return 
$this->_d[$index];
    else if(
$index>=&& $index<$this->_c// in case the value is null
        
return $this->_d[$index];
    else
        throw new 
CException(Yii::t('yii','List index "{index}" is out of bound.',
            array(
'{index}'=>$index)));
}

杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 杩欎釜鏂规硶璺offsetGet鏄畬鍏ㄤ竴鏍风殑銆

mergeWith() 鏂规硶
public void mergeWith(mixed $data)
$data mixed 瑕佸悎骞剁殑鏁版嵁, 鍙兘鏄暟缁勬垨鑰呯户鎵夸簬Traversable鐨勫璞.
婧愮爜锛 framework/collections/CList.php#283 (鏄剧ず)
public function mergeWith($data)
{
    if(
is_array($data) || ($data instanceof Traversable))
    {
        if(
$data instanceof CList)
            
$data=$data->_d;
        foreach(
$data as $item)
            
$this->add($item);
    }
    else if(
$data!==null)
        throw new 
CException(Yii::t('yii','List data must be an array or an object implementing Traversable.'));
}

灏嗚凯浠e櫒鐨勬暟鎹暣鍚堝埌map 鏂扮殑鏁版嵁浼氭坊鍔犲埌宸插瓨鍦ㄧ殑鏁版嵁鍚庨潰銆

offsetExists() 鏂规硶
public boolean offsetExists(integer $offset)
$offset integer 瑕佹鏌ョ殑浣嶇疆
{return} boolean
婧愮爜锛 framework/collections/CList.php#302 (鏄剧ず)
public function offsetExists($offset)
{
    return (
$offset>=&& $offset<$this->_c);
}

杩斿洖鍊艰鏄庡垪琛ㄤ腑鏄惁鍖呭惈杩欎釜椤圭洰銆 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

offsetGet() 鏂规硶
public mixed offsetGet(integer $offset)
$offset integer 瑕佹彃鍏ラ」鐩殑绱㈠紩銆
{return} mixed 杩斿洖璇ョ储寮曠殑椤圭洰銆
婧愮爜锛 framework/collections/CList.php#314 (鏄剧ず)
public function offsetGet($offset)
{
    return 
$this->itemAt($offset);
}

杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

offsetSet() 鏂规硶
public void offsetSet(integer $offset, mixed $item)
$offset integer 瑕佽缃」鐩殑浣嶇疆
$item mixed 椤圭洰瀵硅薄
婧愮爜锛 framework/collections/CList.php#325 (鏄剧ず)
public function offsetSet($offset,$item)
{
    if(
$offset===null || $offset===$this->_c)
        
$this->insertAt($this->_c,$item);
    else
    {
        
$this->removeAt($offset);
        
$this->insertAt($offset,$item);
    }
}

鍦ㄦ寚瀹氫綅缃彃鍏ラ」鐩 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

offsetUnset() 鏂规硶
public void offsetUnset(integer $offset)
$offset integer 瑕佸垹闄ょ殑椤圭洰銆
婧愮爜锛 framework/collections/CList.php#341 (鏄剧ず)
public function offsetUnset($offset)
{
    
$this->removeAt($offset);
}

鍒犻櫎鎸囧畾浣嶇疆鐨勯」鐩 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

remove() 鏂规硶
public integer remove(mixed $item)
$item mixed 瑕佸垹闄ょ殑椤圭洰鐨勭储寮曘
{return} integer 杩斿洖宸茬粡鍒犻櫎鐨勯」鐩殑绱㈠紩銆
婧愮爜锛 framework/collections/CList.php#177 (鏄剧ず)
public function remove($item)
{
    if((
$index=$this->indexOf($item))>=0)
    {
        
$this->removeAt($index);
        return 
$index;
    }
    else
        return 
false;
}

浠庡垪琛ㄤ腑鍒犻櫎涓涓」鐩 杩欎釜鍒楄〃棣栧厛浼氭悳绱㈣繖涓」鐩 鍦ㄥ垪琛ㄤ腑绗竴涓壘鍒扮殑椤圭洰浼氳鍒犻櫎銆(涔熷氨鏄, 鍒楄〃涓彲鑳藉瓨鍦ㄧ潃鐩稿悓鐨勯」鐩)

removeAt() 鏂规硶
public mixed removeAt(integer $index)
$index integer 瑕佸垹闄ょ殑椤圭洰鐨勭储寮曘
{return} mixed 杩斿洖宸茬粡鍒犻櫎鐨勯」鐩
婧愮爜锛 framework/collections/CList.php#194 (鏄剧ず)
public function removeAt($index)
{
    if(!
$this->_r)
    {
        if(
$index>=&& $index<$this->_c)
        {
            
$this->_c--;
            if(
$index===$this->_c)
                return 
array_pop($this->_d);
            else
            {
                
$item=$this->_d[$index];
                
array_splice($this->_d,$index,1);
                return 
$item;
            }
        }
        else
            throw new 
CException(Yii::t('yii','List index "{index}" is out of bound.',
                array(
'{index}'=>$index)));
    }
    else
        throw new 
CException(Yii::t('yii','The list is read only.'));
}

鍒犻櫎鎸囧畾浣嶇疆鐨勯」鐩

setReadOnly() 鏂规硶
protected void setReadOnly(boolean $value)
$value boolean 璁剧疆杩欎釜鍒楄〃鏄惁涓哄彧璇
婧愮爜锛 framework/collections/CList.php#79 (鏄剧ず)
protected function setReadOnly($value)
{
    
$this->_r=$value;
}

toArray() 鏂规硶
public array toArray()
{return} array 鏁扮粍涓殑椤圭洰鍒楄〃
婧愮爜锛 framework/collections/CList.php#251 (鏄剧ず)
public function toArray()
{
    return 
$this->_d;
}

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