PHP Class Prado\Collections\TMap

TMap implements a collection that takes key-value pairs. You can access, add or remove an item with a key by using {@link itemAt}, {@link add}, and {@link remove}. To get the number of the items in the map, use {@link getCount}. TMap can also be used like a regular array as follows, $map[$key]=$value; // add a key-value pair unset($map[$key]); // remove the value with the specified key if(isset($map[$key])) // if the map contains the key foreach($map as $key=>$value) // traverse the items in the map $n=count($map); // returns the number of items in the map
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends Prado\TComponent, implements IteratorAggregate, implements ArrayAccess, implements Countable
ファイルを表示 Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__construct ( $data = null, $readOnly = false ) Constructor.
add ( $key, $value ) Adds an item into the map.
clear ( ) Removes all items in the map.
contains ( $key ) : boolean
copyFrom ( $data ) Copies iterable data into the map.
count ( ) : integer Returns the number of items in the map.
getCount ( ) : integer
getIterator ( ) : Iterator Returns an iterator for traversing the items in the list.
getKeys ( ) : array
getReadOnly ( ) : boolean
itemAt ( $key ) : mixed Returns the item with the specified key.
mergeWith ( $data ) Merges iterable data into the map.
offsetExists ( $offset ) : boolean Returns whether there is an element at the specified offset.
offsetGet ( $offset ) : mixed Returns the element at the specified offset.
offsetSet ( $offset, $item ) Sets the element at the specified offset.
offsetUnset ( $offset ) Unsets the element at the specified offset.
remove ( $key ) : mixed Removes an item from the map by its key.
toArray ( ) : array

Protected Methods

Method Description
_getZappableSleepProps ( &$exprops ) Returns an array with the names of all variables of this object that should NOT be serialized because their value is the default one or useless to be cached for the next page loads.
setReadOnly ( $value )

Method Details

__construct() public method

Initializes the list with an array or an iterable object.
public __construct ( $data = null, $readOnly = false )

_getZappableSleepProps() protected method

Reimplement in derived classes to add new variables, but remember to also to call the parent implementation first.
protected _getZappableSleepProps ( &$exprops )

add() public method

Note, if the specified key already exists, the old value will be overwritten.
public add ( $key, $value )

clear() public method

Removes all items in the map.
public clear ( )

contains() public method

public contains ( $key ) : boolean
return boolean whether the map contains an item with the specified key

copyFrom() public method

Note, existing data in the map will be cleared first.
public copyFrom ( $data )

count() public method

This method is required by \Countable interface.
public count ( ) : integer
return integer number of items in the map.

getCount() public method

public getCount ( ) : integer
return integer the number of items in the map

getIterator() public method

This method is required by the interface \IteratorAggregate.
public getIterator ( ) : Iterator
return Iterator an iterator for traversing the items in the list.

getKeys() public method

public getKeys ( ) : array
return array the key list

getReadOnly() public method

public getReadOnly ( ) : boolean
return boolean whether this map is read-only or not. Defaults to false.

itemAt() public method

This method is exactly the same as {@link offsetGet}.
public itemAt ( $key ) : mixed
return mixed the element at the offset, null if no element is found at the offset

mergeWith() public method

Existing data in the map will be kept and overwritten if the keys are the same.
public mergeWith ( $data )

offsetExists() public method

This method is required by the interface \ArrayAccess.
public offsetExists ( $offset ) : boolean
return boolean

offsetGet() public method

This method is required by the interface \ArrayAccess.
public offsetGet ( $offset ) : mixed
return mixed the element at the offset, null if no element is found at the offset

offsetSet() public method

This method is required by the interface \ArrayAccess.
public offsetSet ( $offset, $item )

offsetUnset() public method

This method is required by the interface \ArrayAccess.
public offsetUnset ( $offset )

remove() public method

Removes an item from the map by its key.
public remove ( $key ) : mixed
return mixed the removed value, null if no such key exists.

setReadOnly() protected method

protected setReadOnly ( $value )

toArray() public method

public toArray ( ) : array
return array the list of items in array