CAttributeCollection

优质
小牛编辑
125浏览
2023-12-01
所有包 | 属性 | 方法
system.collections
继承class CAttributeCollection » CMap » CComponent
实现Countable, ArrayAccess, Traversable, IteratorAggregate
源自1.0
版本$Id: CAttributeCollection.php 3515 2011-12-28 12:29:24Z mdomba $
源码framework/collections/CAttributeCollection.php
CAttributeCollection实现了为储存的属性名称和值的集合。

除CMap提供的所有功能外,CAttributeCollection 允许你像getting和setting属性一样获取和设置 属性值。例如,下面的用法对于一个CAttributeCollection对象来说, 都是有效的:
$collection->text='text'; // 等价于:$collection->add('text','text');
echo $collection->text;   // 等价于:echo $collection->itemAt('text');


属性名称的大小写敏感可以通过集合的 caseSensitive属性开启或关闭。

公共属性

隐藏继承属性

属性类型描述定义在
caseSensitiveboolean键名是否大小写敏感。默认为false。CAttributeCollection
countinteger返回map中的项目数。CMap
iteratorCMapIterator返回遍历这个列表的项目的迭代器。CMap
keysarray返回键名列表CMap
readOnlyboolean返回值说明这个列表是否为只读。默认为false。CMap

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造方法。CMap
__get()通过属性或事件名返回一个属性值或一个事件处理程序列表。CAttributeCollection
__isset()检测一个属性值是否为null。CAttributeCollection
__set()设置一个组件属性的值。CAttributeCollection
__unset()设置一个组件属性为null。CAttributeCollection
add()添加一个项到map。CAttributeCollection
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定一个属性是否可读。CAttributeCollection
canSetProperty()确定一个属性是否可设置。CAttributeCollection
clear()删除map中所有项目。CMap
contains()返回值说明指定的项目是否在map中。CAttributeCollection
copyFrom()将迭代器中的数据复制到map。CMap
count()返回map中的项目数。CMap
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getCount()返回map中的项目数。CMap
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getIterator()返回遍历这个列表的项目的迭代器。CMap
getKeys()返回返回键名列表CMap
getReadOnly()返回返回值说明这个列表是否为只读。默认为false。CMap
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定是否一个属性已定义。CAttributeCollection
itemAt()返回指定键的项。CAttributeCollection
mergeArray()递归合并两个或多个数组。CMap
mergeWith()将迭代器的数据整合到map。CMap
offsetExists()返回值说明指定位置是否存在元素。CMap
offsetGet()返回值指定位置的元素。CMap
offsetSet()设置指定位置的元素。CMap
offsetUnset()删除指定位置的元素。CMap
raiseEvent()发起一个事件。CComponent
remove()通过它的键从map中移除一个项目。CAttributeCollection
toArray()CMap

受保护方法

隐藏继承方法

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

属性详细

caseSensitive 属性 public boolean $caseSensitive;

键名是否大小写敏感。默认为false。

方法详细

__get() 方法
public mixed __get(string $name)
$namestring属性名或事件名
{return}mixed属性值或事件处理程序列表
源码: framework/collections/CAttributeCollection.php#47 (显示) publicfunction__get($name)
{
if($this->contains($name))
return$this->itemAt($name);
else
returnparent::__get($name);
}

通过属性或事件名返回一个属性值或一个事件处理程序列表。 这个方法通过返回一个键值是否存在于集合来 覆盖父类方法。

__isset() 方法
public boolean __isset(string $name)
$namestring属性名或事件名
{return}boolean返回值说明属性值是否为null
源码: framework/collections/CAttributeCollection.php#75 (显示) publicfunction__isset($name)
{
if($this->contains($name))
return$this->itemAt($name)!==null;
else
returnparent::__isset($name);
}

检测一个属性值是否为null。 这个方法通过检查键名是否存在于集合当中,并且为非null值,达到 覆盖父类方法实现。

__set() 方法
public void __set(string $name, mixed $value)
$namestring属性名或事件名
$valuemixed属性值或事件处理程序
源码: framework/collections/CAttributeCollection.php#63 (显示) publicfunction__set($name,$value)
{
$this->add($name,$value);
}

设置一个组件属性的值。 这个方法通过添加一个新的键名和键值到集合,达到 覆盖父类方法实现。

__unset() 方法
public void __unset(string $name)
$namestring属性名或事件名
源码: framework/collections/CAttributeCollection.php#89 (显示) publicfunction__unset($name)
{
$this->remove($name);
}

设置一个组件属性为null。 这个方法通过清除指定的键名键值,达到 覆盖父类方法实现。

add() 方法
public void add(mixed $key, mixed $value)
$keymixedkey
$valuemixedvalue
源码: framework/collections/CAttributeCollection.php#114 (显示) publicfunctionadd($key,$value)
{
if($this->caseSensitive)
parent::add($key,$value);
else
parent::add(strtolower($key),$value);
}

添加一个项到map。 这个方法是,如果caseSensitive为false,则先将键名转换成小写,达到覆盖父类方法实现。

canGetProperty() 方法
public boolean canGetProperty(string $name)
$namestring属性名
{return}boolean返回值说明该属性是否可读
源码: framework/collections/CAttributeCollection.php#169 (显示) publicfunctioncanGetProperty($name)
{
return$this->contains($name)||parent::canGetProperty($name);
}

确定一个属性是否可读。 这个方法是,如果集合中包含此键名对应的键值,则返回true,达到 覆盖父类方法实现。

canSetProperty() 方法
public boolean canSetProperty(string $name)
$namestringthe property name
{return}booleantrue
源码: framework/collections/CAttributeCollection.php#181 (显示) publicfunctioncanSetProperty($name)
{
returntrue;
}

确定一个属性是否可设置。 这个方法通过返回真覆盖父类方法实现。 因为你总是增加一个新值到集合。

contains() 方法
public boolean contains(mixed $key)
$keymixed键名
{return}boolean返回值说明map是否包含着指定键名对应的项目。
源码: framework/collections/CAttributeCollection.php#142 (显示) publicfunctioncontains($key)
{
if($this->caseSensitive)
returnparent::contains($key);
else
returnparent::contains(strtolower($key));
}

返回值说明指定的项目是否在map中。 这个方法是,如果caseSensitive为false,则先将键名转换成小写,达到覆盖父类方法实现。

hasProperty() 方法
public boolean hasProperty(string $name)
$namestring属性名
{return}boolean返回值说明该属性是否被定义
源码: framework/collections/CAttributeCollection.php#157 (显示) publicfunctionhasProperty($name)
{
return$this->contains($name)||parent::hasProperty($name);
}

确定是否一个属性已定义。 这个方法是,如果集合中包含此键名对应的键值,则返回true,达到 覆盖父类方法实现。

itemAt() 方法
public mixed itemAt(mixed $key)
$keymixed键名
{return}mixed返回在偏移量位置的元素,如果在此偏移位置此元素没找到则返回null。
源码: framework/collections/CAttributeCollection.php#100 (显示) publicfunctionitemAt($key)
{
if($this->caseSensitive)
returnparent::itemAt($key);
else
returnparent::itemAt(strtolower($key));
}

返回指定键的项。 这个方法是,如果caseSensitive为false,则先将键名转换成小写,达到覆盖父类方法实现。

remove() 方法
public mixed remove(mixed $key)
$keymixed被移除的项目的键名。
{return}mixed返回移除的键值,如果键名不存在则返回null。
源码: framework/collections/CAttributeCollection.php#128 (显示) publicfunctionremove($key)
{
if($this->caseSensitive)
returnparent::remove($key);
else
returnparent::remove(strtolower($key));
}

通过它的键从map中移除一个项目。 这个方法是,如果caseSensitive为false,则先将键名转换成小写,达到覆盖父类方法实现。