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
Afficher le fichier Open project: pradosoft/prado Class Usage Examples

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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

_getZappableSleepProps() protected méthode

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

add() public méthode

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

clear() public méthode

Removes all items in the map.
public clear ( )

contains() public méthode

public contains ( $key ) : boolean
Résultat boolean whether the map contains an item with the specified key

copyFrom() public méthode

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

count() public méthode

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

getCount() public méthode

public getCount ( ) : integer
Résultat integer the number of items in the map

getIterator() public méthode

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

getKeys() public méthode

public getKeys ( ) : array
Résultat array the key list

getReadOnly() public méthode

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

itemAt() public méthode

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

mergeWith() public méthode

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

offsetExists() public méthode

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

offsetGet() public méthode

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

offsetSet() public méthode

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

offsetUnset() public méthode

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

remove() public méthode

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

setReadOnly() protected méthode

protected setReadOnly ( $value )

toArray() public méthode

public toArray ( ) : array
Résultat array the list of items in array