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

CAttributeCollection

system.collections
继承 class CAttributeCollection » CMap » CComponent
实现 Countable, ArrayAccess, Traversable, IteratorAggregate
可用自 1.0
源码 framework/collections/CAttributeCollection.php
CAttributeCollection implements a collection for storing attribute names and values.

Besides all functionalities provided by CMap, CAttributeCollection allows you to get and set attribute values like getting and setting properties. For example, the following usages are all valid for a CAttributeCollection object:
$collection->text='text'; // same as:  $collection->add('text','text');
echo $collection->text;   // same as:  echo $collection->itemAt('text');


The case sensitivity of attribute names can be toggled by setting the caseSensitive property of the collection.

公共属性

隐藏继承的属性

属性类型描述被定义在
caseSensitive boolean whether the keys are case-sensitive. CAttributeCollection
count integer Returns the number of items in the map. CMap
iterator CMapIterator Returns an iterator for traversing the items in the list. CMap
keys array the key list CMap
readOnly boolean whether this map is read-only or not. CMap

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CMap
__get() Returns a property value or an event handler list by property or event name. CAttributeCollection
__isset() Checks if a property value is null. CAttributeCollection
__set() Sets value of a component property. CAttributeCollection
__unset() Sets a component property to be null. CAttributeCollection
add() Adds an item into the map. CAttributeCollection
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. CAttributeCollection
canSetProperty() Determines whether a property can be set. CAttributeCollection
clear() Removes all items in the map. CMap
contains() Returns whether the specified is in the map. CAttributeCollection
copyFrom() Copies iterable data into the map. CMap
count() Returns the number of items in the map. CMap
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 map. CMap
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getIterator() Returns an iterator for traversing the items in the list. CMap
getKeys() Returns the key list CMap
getReadOnly() Returns whether this map is read-only or not. Defaults to false. CMap
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. CAttributeCollection
itemAt() Returns the item with the specified key. CAttributeCollection
mergeArray() Merges two or more arrays into one recursively. CMap
mergeWith() Merges iterable data into the map. CAttributeCollection
offsetExists() Returns whether there is an element at the specified offset. CMap
offsetGet() Returns the element at the specified offset. CMap
offsetSet() Sets the element at the specified offset. CMap
offsetUnset() Unsets the element at the specified offset. CMap
raiseEvent() Raises an event. CComponent
remove() Removes an item from the map by its key. CAttributeCollection
toArray() CMap

受保护的方法

隐藏继承的方法

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

属性详情

caseSensitive 属性
public boolean $caseSensitive;

whether the keys are case-sensitive. Defaults to false.

方法详情

__get() 方法
public mixed __get(string $name)
$name string the property name or the event name
{return} mixed the property value or the event handler list
源码: framework/collections/CAttributeCollection.php#46 (显示)
public function __get($name)
{
    if(
$this->contains($name))
        return 
$this->itemAt($name);
    else
        return 
parent::__get($name);
}

Returns a property value or an event handler list by property or event name. This method overrides the parent implementation by returning a key value if the key exists in the collection.

__isset() 方法
public boolean __isset(string $name)
$name string the property name or the event name
{return} boolean whether the property value is null
源码: framework/collections/CAttributeCollection.php#74 (显示)
public function __isset($name)
{
    if(
$this->contains($name))
        return 
$this->itemAt($name)!==null;
    else
        return 
parent::__isset($name);
}

Checks if a property value is null. This method overrides the parent implementation by checking if the key exists in the collection and contains a non-null value.

__set() 方法
public void __set(string $name, mixed $value)
$name string the property name or event name
$value mixed the property value or event handler
源码: framework/collections/CAttributeCollection.php#62 (显示)
public function __set($name,$value)
{
    
$this->add($name,$value);
}

Sets value of a component property. This method overrides the parent implementation by adding a new key value to the collection.

__unset() 方法
public void __unset(string $name)
$name string the property name or the event name
源码: framework/collections/CAttributeCollection.php#88 (显示)
public function __unset($name)
{
    
$this->remove($name);
}

Sets a component property to be null. This method overrides the parent implementation by clearing the specified key value.

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

Adds an item into the map. This overrides the parent implementation by converting the key to lower case first if caseSensitive is false.

canGetProperty() 方法
public boolean canGetProperty(string $name)
$name string the property name
{return} boolean whether the property can be read
源码: framework/collections/CAttributeCollection.php#168 (显示)
public function canGetProperty($name)
{
    return 
$this->contains($name) || parent::canGetProperty($name);
}

Determines whether a property can be read. This method overrides parent implementation by returning true if the collection contains the named key.

canSetProperty() 方法
public boolean canSetProperty(string $name)
$name string the property name
{return} boolean true
源码: framework/collections/CAttributeCollection.php#180 (显示)
public function canSetProperty($name)
{
    return 
true;
}

Determines whether a property can be set. This method overrides parent implementation by always returning true because you can always add a new value to the collection.

contains() 方法
public boolean contains(mixed $key)
$key mixed the key
{return} boolean whether the map contains an item with the specified key
源码: framework/collections/CAttributeCollection.php#141 (显示)
public function contains($key)
{
    if(
$this->caseSensitive)
        return 
parent::contains($key);
    else
        return 
parent::contains(strtolower($key));
}

Returns whether the specified is in the map. This overrides the parent implementation by converting the key to lower case first if caseSensitive is false.

hasProperty() 方法
public boolean hasProperty(string $name)
$name string the property name
{return} boolean whether the property is defined
源码: framework/collections/CAttributeCollection.php#156 (显示)
public function hasProperty($name)
{
    return 
$this->contains($name) || parent::hasProperty($name);
}

Determines whether a property is defined. This method overrides parent implementation by returning true if the collection contains the named key.

itemAt() 方法
public mixed itemAt(mixed $key)
$key mixed the key
{return} mixed the element at the offset, null if no element is found at the offset
源码: framework/collections/CAttributeCollection.php#99 (显示)
public function itemAt($key)
{
    if(
$this->caseSensitive)
        return 
parent::itemAt($key);
    else
        return 
parent::itemAt(strtolower($key));
}

Returns the item with the specified key. This overrides the parent implementation by converting the key to lower case first if caseSensitive is false.

mergeWith() 方法
public void mergeWith(mixed $data, boolean $recursive=true)
$data mixed the data to be merged with, must be an array or object implementing Traversable
$recursive boolean whether the merging should be recursive.
源码: framework/collections/CAttributeCollection.php#202 (显示)
public function mergeWith($data,$recursive=true)
{
    if(!
$this->caseSensitive && (is_array($data) || $data instanceof Traversable))
    {
        
$d=array();
        foreach(
$data as $key=>$value)
            
$d[strtolower($key)]=$value;
        return 
parent::mergeWith($d,$recursive);
    }
    
parent::mergeWith($data,$recursive);
}

Merges iterable data into the map.

Existing elements in the map will be overwritten if their keys are the same as those in the source. If the merge is recursive, the following algorithm is performed:

  • the map data is saved as $a, and the source data is saved as $b;
  • if $a and $b both have an array indexed at the same string key, the arrays will be merged using this algorithm;
  • any integer-indexed elements in $b will be appended to $a and reindexed accordingly;
  • any string-indexed elements in $b will overwrite elements in $a with the same index;

remove() 方法
public mixed remove(mixed $key)
$key mixed the key of the item to be removed
{return} mixed the removed value, null if no such key exists.
源码: framework/collections/CAttributeCollection.php#127 (显示)
public function remove($key)
{
    if(
$this->caseSensitive)
        return 
parent::remove($key);
    else
        return 
parent::remove(strtolower($key));
}

Removes an item from the map by its key. This overrides the parent implementation by converting the key to lower case first if caseSensitive is false.