Class CAttributeCollection
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 CAttributeCollection::$caseSensitive
property of the collection.
-
CComponent
-
CMap
implements
IteratorAggregate,
ArrayAccess,
Countable
-
CAttributeCollection
Methods summary
public
mixed
|
#
__get( string $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.
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.
Parameters
- $name
string $name the property name or the event name
Returns
mixed the property value or the event handler list
Throws
Overrides
|
public
mixed
|
#
__set( string $name, mixed $value )
Sets value of a component property. This method overrides the parent
implementation by adding a new key value to the collection.
Sets value of a component property. This method overrides the parent
implementation by adding a new key value to the collection.
Parameters
- $name
string $name the property name or event name
- $value
mixed $value the property value or event handler
Returns
mixed
Throws
CException
If the property is not defined or read-only.
Overrides
|
public
boolean
|
#
__isset( string $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.
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.
Parameters
- $name
string $name the property name or the event name
Returns
boolean whether the property value is null
Overrides
|
public
mixed
|
#
__unset( string $name )
Sets a component property to be null. This method overrides the parent
implementation by clearing the specified key value.
Sets a component property to be null. This method overrides the parent
implementation by clearing the specified key value.
Parameters
- $name
string $name the property name or the event name
Returns
mixed
Throws
Overrides
|
public
mixed
|
#
itemAt( mixed $key )
Returns the item with the specified key. This overrides the parent
implementation by converting the key to lower case first if CAttributeCollection::$caseSensitive is false.
Parameters
Returns
mixed the element at the offset, null if no element is found at the offset
Overrides
|
public
|
#
add( mixed $key, mixed $value )
Adds an item into the map. This overrides the parent implementation by
converting the key to lower case first if CAttributeCollection::$caseSensitive is false.
Parameters
- $key
mixed $key key
- $value
mixed $value value
Throws
Overrides
|
public
mixed
|
#
remove( mixed $key )
Removes an item from the map by its key. This overrides the parent
implementation by converting the key to lower case first if CAttributeCollection::$caseSensitive is false.
Parameters
- $key
mixed $key the key of the item to be removed
Returns
mixed the removed value, null if no such key exists.
Throws
Overrides
|
public
boolean
|
#
contains( mixed $key )
Returns whether the specified is in the map. This overrides the parent
implementation by converting the key to lower case first if CAttributeCollection::$caseSensitive is false.
Parameters
Returns
boolean whether the map contains an item with the specified key
Overrides
|
public
boolean
|
#
hasProperty( string $name )
Determines whether a property is defined. This method overrides parent
implementation by returning true if the collection contains the named key.
Determines whether a property is defined. This method overrides parent
implementation by returning true if the collection contains the named key.
Parameters
- $name
string $name the property name
Returns
boolean whether the property is defined
Overrides
|
public
boolean
|
#
canGetProperty( string $name )
Determines whether a property can be read. This method overrides parent
implementation by returning true if the collection contains the named key.
Determines whether a property can be read. This method overrides parent
implementation by returning true if the collection contains the named key.
Parameters
- $name
string $name the property name
Returns
boolean whether the property can be read
Overrides
|
public
boolean
|
#
canSetProperty( string $name )
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.
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.
Parameters
- $name
string $name the property name
Returns
boolean true
Overrides
|
public
|
#
mergeWith( mixed $data, boolean $recursive = true )
Merges iterable data into the map.
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;
Parameters
- $data
mixed $data the data to be merged with, must be an array or object implementing
Traversable
- $recursive
boolean $recursive whether the merging should be recursive.
Throws
CException
If data is neither an array nor an iterator.
Overrides
|
Methods inherited from CMap
__construct(),
clear(),
copyFrom(),
count(),
getCount(),
getIterator(),
getKeys(),
getReadOnly(),
mergeArray(),
offsetExists(),
offsetGet(),
offsetSet(),
offsetUnset(),
setReadOnly(),
toArray()
|
Methods inherited from CComponent
__call(),
asa(),
attachBehavior(),
attachBehaviors(),
attachEventHandler(),
detachBehavior(),
detachBehaviors(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
getEventHandlers(),
hasEvent(),
hasEventHandler(),
raiseEvent()
|
Properties summary
public
boolean
|
$caseSensitive
|
false |
#
whether the keys are case-sensitive. Defaults to false.
whether the keys are case-sensitive. Defaults to false.
|