Yii Framework v1.1.10 绫诲弬鑰

CMap

system.collections
缁ф壙 class CMap » CComponent
瀹炵幇 IteratorAggregate, Traversable, ArrayAccess, Countable
瀛愮被 CAttributeCollection, CConfiguration, CCookieCollection, CFormElementCollection, CTypedMap
婧愯嚜 1.0
鐗堟湰 $Id: CMap.php 3518 2011-12-28 23:31:29Z alexander.makarow $
婧愮爜 framework/collections/CMap.php
CMap瀹炵幇浜嗕竴涓敭鍚嶏紞閿煎鐨勯泦鍚.

浣犲彲浠ラ氳繃浣跨敤 itemAtadd锛屼互鍙remove璁块棶锛屾坊鍔狅紝鍒犻櫎椤圭洰銆 閫氳繃璋冪敤getCount鍙幏寰楀湪map鐨勯」鐩暟閲忋 CMap鍚屾牱涔熷彲浠ュ儚涓涓櫘閫氱殑鏁扮粍浣跨敤锛屽
$map[$key]=$value; //娣诲姞涓涓敭鍚嶏紞閿煎
unset($map[$key]); //鍒犻櫎鎸囧畾閿悕鐨勯敭鍊
if(isset($map[$key])) //濡傛灉map鍖呭惈閿
foreach($map as $key=>$value) //閬嶅巻map鐨勯」鐩
$n=count($map);  //杩斿洖map涓殑椤圭洰鏁

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
count integer 杩斿洖map涓殑椤圭洰鏁般 CMap
iterator CMapIterator 杩斿洖閬嶅巻杩欎釜鍒楄〃鐨勯」鐩殑杩唬鍣ㄣ CMap
keys array 杩斿洖閿悕鍒楄〃 CMap
readOnly boolean 杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆 CMap

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犳柟娉曘 CMap
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
add() 娣诲姞涓涓」鐩埌map銆 CMap
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clear() 鍒犻櫎map涓墍鏈夐」鐩 CMap
contains() CMap
copyFrom() 灏嗚凯浠e櫒涓殑鏁版嵁澶嶅埗鍒癿ap銆 CMap
count() 杩斿洖map涓殑椤圭洰鏁般 CMap
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getCount() 杩斿洖map涓殑椤圭洰鏁般 CMap
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIterator() 杩斿洖閬嶅巻杩欎釜鍒楄〃鐨勯」鐩殑杩唬鍣ㄣ CMap
getKeys() 杩斿洖杩斿洖閿悕鍒楄〃 CMap
getReadOnly() 杩斿洖杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆 CMap
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
itemAt() 杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 CMap
mergeArray() 閫掑綊鍚堝苟涓や釜鎴栧涓暟缁勩 CMap
mergeWith() 灏嗚凯浠e櫒鐨勬暟鎹暣鍚堝埌map銆 CMap
offsetExists() 杩斿洖鍊艰鏄庢寚瀹氫綅缃槸鍚﹀瓨鍦ㄥ厓绱犮 CMap
offsetGet() 杩斿洖鍊兼寚瀹氫綅缃殑鍏冪礌銆 CMap
offsetSet() 璁剧疆鎸囧畾浣嶇疆鐨勫厓绱犮 CMap
offsetUnset() 鍒犻櫎鎸囧畾浣嶇疆鐨勫厓绱犮 CMap
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
remove() 鏍规嵁閿悕浠巑ap涓垹闄や竴涓」鐩 CMap
toArray() CMap

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

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

灞炴ц缁

count 灞炴 鍙
public integer getCount()

杩斿洖map涓殑椤圭洰鏁般

iterator 灞炴 鍙

杩斿洖閬嶅巻杩欎釜鍒楄〃鐨勯」鐩殑杩唬鍣ㄣ 姝ゆ柟娉曚负鎺ュ彛IteratorAggregate寮哄埗瑕佹眰瀹炵幇銆

keys 灞炴 鍙
public array getKeys()

杩斿洖閿悕鍒楄〃

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/CMap.php#54 (鏄剧ず)
public function __construct($data=null,$readOnly=false)
{
    if(
$data!==null)
        
$this->copyFrom($data);
    
$this->setReadOnly($readOnly);
}

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

add() 鏂规硶
public void add(mixed $key, mixed $value)
$key mixed 閿悕
$value mixed 閿
婧愮爜锛 framework/collections/CMap.php#135 (鏄剧ず)
public function add($key,$value)
{
    if(!
$this->_r)
    {
        if(
$key===null)
            
$this->_d[]=$value;
        else
            
$this->_d[$key]=$value;
    }
    else
        throw new 
CException(Yii::t('yii','The map is read only.'));
}

娣诲姞涓涓」鐩埌map銆 璇锋敞鎰忥紝濡傛灉鎸囧畾鐨勯敭宸茬粡瀛樺湪锛屾棫鍊煎皢琚鐩栥

clear() 鏂规硶
public void clear()
婧愮爜锛 framework/collections/CMap.php#178 (鏄剧ず)
public function clear()
{
    foreach(
array_keys($this->_d) as $key)
        
$this->remove($key);
}

鍒犻櫎map涓墍鏈夐」鐩

contains() 鏂规硶
public boolean contains(mixed $key)
$key mixed 閿悕
{return} boolean 杩斿洖鍊艰鏄巑ap涓槸鍚﹀寘鍚寚瀹氶敭鍚嶅搴旂殑閿笺
婧愮爜锛 framework/collections/CMap.php#188 (鏄剧ず)
public function contains($key)
{
    return isset(
$this->_d[$key]) || array_key_exists($key,$this->_d);
}

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

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

count() 鏂规硶
public integer count()
{return} integer 杩斿洖map涓殑椤圭洰鏁般
婧愮爜锛 framework/collections/CMap.php#92 (鏄剧ず)
public function count()
{
    return 
$this->getCount();
}

杩斿洖map涓殑椤圭洰鏁般 姝ゆ柟娉曚负鎺ュ彛Countable寮哄埗瑕佹眰瀹炵幇銆

getCount() 鏂规硶
public integer getCount()
{return} integer 杩斿洖map涓殑椤圭洰鏁
婧愮爜锛 framework/collections/CMap.php#101 (鏄剧ず)
public function getCount()
{
    return 
count($this->_d);
}

杩斿洖map涓殑椤圭洰鏁般

getIterator() 鏂规硶
public CMapIterator getIterator()
{return} CMapIterator 杩斿洖閬嶅巻鍒楄〃涓厓绱犵殑杩唬鍣ㄣ
婧愮爜锛 framework/collections/CMap.php#82 (鏄剧ず)
public function getIterator()
{
    return new 
CMapIterator($this->_d);
}

杩斿洖閬嶅巻杩欎釜鍒楄〃鐨勯」鐩殑杩唬鍣ㄣ 姝ゆ柟娉曚负鎺ュ彛IteratorAggregate寮哄埗瑕佹眰瀹炵幇銆

getKeys() 鏂规硶
public array getKeys()
{return} array 杩斿洖閿悕鍒楄〃
婧愮爜锛 framework/collections/CMap.php#109 (鏄剧ず)
public function getKeys()
{
    return 
array_keys($this->_d);
}

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

itemAt() 鏂规硶
public mixed itemAt(mixed $key)
$key mixed 椤圭洰鐨勭储寮曞
{return} mixed 杩斿洖鎸囧畾浣嶇疆鐨勫厓绱狅紝濡傛灉杩欎釜浣嶇疆娌℃湁鍏冪礌瀛樺湪锛屽垯杩斿洖null銆
婧愮爜锛 framework/collections/CMap.php#120 (鏄剧ず)
public function itemAt($key)
{
    if(isset(
$this->_d[$key]))
        return 
$this->_d[$key];
    else
        return 
null;
}

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

mergeArray() 鏂规硶
public static array mergeArray(array $a, array $b)
$a array 瑕佽鍚堝苟鐨勬暟缁
$b array 瑕佽繘琛屽悎骞剁殑鏁扮粍銆備綘鍙互閫氳繃绗笁锛屽洓銆傘傘 鎸囧畾棰濆銆
{return} array 杩斿洖鍚堝苟鍚庣殑鏁扮粍锛堝師鏁扮粍涓嶄細鍙戠敓鏀瑰彉銆傦級
婧愮爜锛 framework/collections/CMap.php#281 (鏄剧ず)
public static function mergeArray($a,$b)
{
    
$args=func_get_args();
    
$res=array_shift($args);
    while(!empty(
$args))
    {
        
$next=array_shift($args);
        foreach(
$next as $k => $v)
        {
            if(
is_integer($k))
                isset(
$res[$k]) ? $res[]=$v $res[$k]=$v;
            else if(
is_array($v) && isset($res[$k]) && is_array($res[$k]))
                
$res[$k]=self::mergeArray($res[$k],$v);
            else
                
$res[$k]=$v;
        }
    }
    return 
$res;
}

閫掑綊鍚堝苟涓や釜鎴栧涓暟缁勩 濡傛灉姣忎釜鏁扮粍閮藉寘鍚潃鐩稿悓绱㈠紩鐨勫厓绱狅紝鍒欏悗闈㈢殑 浼氳鐩栧墠闈㈢殑锛堣繖涓窡array_merge_recursive鏈夊尯鍒級銆 濡傛灉涓や釜鏁扮粍鐨勫厓绱犳槸鏁扮粍锛屼笖鏄浉鍚岀殑閿悕锛屽垯浼 杩涜閫掑綊鍚堝苟銆 瀵逛簬浠ユ暟瀛椾綔涓洪敭鍚嶇殑鍏冪礌锛屽悗闈㈡暟缁勭殑鍏冪礌浼氭坊鍔犲埌 鍓嶉潰鐨勬暟缁勯噷闈€

鍙傝

mergeWith() 鏂规硶
public void mergeWith(mixed $data, boolean $recursive=true)
$data mixed 瑕佸悎骞剁殑鏁版嵁, 鍙兘鏄暟缁勬垨鑰呯户鎵夸簬Traversable鐨勫璞
$recursive boolean 鏍囪瘑鏄惁杩涜閫掑綊鍚堝苟銆
婧愮爜锛 framework/collections/CMap.php#239 (鏄剧ず)
public function mergeWith($data,$recursive=true)
{
    if(
is_array($data) || $data instanceof Traversable)
    {
        if(
$data instanceof CMap)
            
$data=$data->_d;
        if(
$recursive)
        {
            if(
$data instanceof Traversable)
            {
                
$d=array();
                foreach(
$data as $key=>$value)
                    
$d[$key]=$value;
                
$this->_d=self::mergeArray($this->_d,$d);
            }
            else
                
$this->_d=self::mergeArray($this->_d,$data);
        }
        else
        {
            foreach(
$data as $key=>$value)
                
$this->add($key,$value);
        }
    }
    else if(
$data!==null)
        throw new 
CException(Yii::t('yii','Map data must be an array or an object implementing Traversable.'));
}

灏嗚凯浠e櫒鐨勬暟鎹暣鍚堝埌map銆

濡傛灉婧愪腑鐨勭殑閿肩浉鍚岋紝map涓殑鐜版湁鍏冪礌灏嗚瑕嗙洊銆 濡傛灉鍚堝苟鏄掑綊鐨勶紝鎵ц涓嬮潰鐨勭畻娉曪細

offsetExists() 鏂规硶
public boolean offsetExists(mixed $offset)
$offset mixed 瑕佹鏌ョ殑浣嶇疆
{return} boolean
婧愮爜锛 framework/collections/CMap.php#307 (鏄剧ず)
public function offsetExists($offset)
{
    return 
$this->contains($offset);
}

杩斿洖鍊艰鏄庢寚瀹氫綅缃槸鍚﹀瓨鍦ㄥ厓绱犮 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

offsetGet() 鏂规硶
public mixed offsetGet(integer $offset)
$offset integer 瑕佹鏌ョ殑浣嶇疆銆
{return} mixed 杩斿洖杩欎釜浣嶇疆鐨勫厓绱狅紝濡傛灉璇ヤ綅缃笉瀛樺湪鍏冪礌锛屽垯杩斿洖null銆
婧愮爜锛 framework/collections/CMap.php#318 (鏄剧ず)
public function offsetGet($offset)
{
    return 
$this->itemAt($offset);
}

杩斿洖鍊兼寚瀹氫綅缃殑鍏冪礌銆 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

offsetSet() 鏂规硶
public void offsetSet(integer $offset, mixed $item)
$offset integer 瑕佽缃厓绱犵殑浣嶇疆
$item mixed 鍏冪礌瀵硅薄
婧愮爜锛 framework/collections/CMap.php#329 (鏄剧ず)
public function offsetSet($offset,$item)
{
    
$this->add($offset,$item);
}

璁剧疆鎸囧畾浣嶇疆鐨勫厓绱犮 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

offsetUnset() 鏂规硶
public void offsetUnset(mixed $offset)
$offset mixed 瑕佸垹闄ょ殑鍏冪礌鐨勪綅缃
婧愮爜锛 framework/collections/CMap.php#339 (鏄剧ず)
public function offsetUnset($offset)
{
    
$this->remove($offset);
}

鍒犻櫎鎸囧畾浣嶇疆鐨勫厓绱犮 姝ゆ柟娉曚负鎺ュ彛ArrayAccess寮哄埗瑕佹眰瀹炵幇銆

remove() 鏂规硶
public mixed remove(mixed $key)
$key mixed 瑕佸垹闄ょ殑椤圭洰鐨勯敭鍚
{return} mixed 杩斿洖宸茬粡鍒犻櫎鐨勫硷紝濡傛灉娌℃湁杩欐牱鐨勯」鐩瓨鍦紝鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/collections/CMap.php#154 (鏄剧ず)
public function remove($key)
{
    if(!
$this->_r)
    {
        if(isset(
$this->_d[$key]))
        {
            
$value=$this->_d[$key];
            unset(
$this->_d[$key]);
            return 
$value;
        }
        else
        {
            
// it is possible the value is null, which is not detected by isset
            
unset($this->_d[$key]);
            return 
null;
        }
    }
    else
        throw new 
CException(Yii::t('yii','The map is read only.'));
}

鏍规嵁閿悕浠巑ap涓垹闄や竴涓」鐩

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

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

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