PHP Класс 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
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\TComponent, implements IteratorAggregate, implements ArrayAccess, implements Countable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
_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 )

Описание методов

__construct() публичный Метод

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

_getZappableSleepProps() защищенный Метод

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

add() публичный Метод

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

clear() публичный Метод

Removes all items in the map.
public clear ( )

contains() публичный Метод

public contains ( $key ) : boolean
Результат boolean whether the map contains an item with the specified key

copyFrom() публичный Метод

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

count() публичный Метод

This method is required by \Countable interface.
public count ( ) : integer
Результат integer number of items in the map.

getCount() публичный Метод

public getCount ( ) : integer
Результат integer the number of items in the map

getIterator() публичный Метод

This method is required by the interface \IteratorAggregate.
public getIterator ( ) : Iterator
Результат Iterator an iterator for traversing the items in the list.

getKeys() публичный Метод

public getKeys ( ) : array
Результат array the key list

getReadOnly() публичный Метод

public getReadOnly ( ) : boolean
Результат boolean whether this map is read-only or not. Defaults to false.

itemAt() публичный Метод

This method is exactly the same as {@link offsetGet}.
public itemAt ( $key ) : mixed
Результат mixed the element at the offset, null if no element is found at the offset

mergeWith() публичный Метод

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

offsetExists() публичный Метод

This method is required by the interface \ArrayAccess.
public offsetExists ( $offset ) : boolean
Результат boolean

offsetGet() публичный Метод

This method is required by the interface \ArrayAccess.
public offsetGet ( $offset ) : mixed
Результат mixed the element at the offset, null if no element is found at the offset

offsetSet() публичный Метод

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

offsetUnset() публичный Метод

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

remove() публичный Метод

Removes an item from the map by its key.
public remove ( $key ) : mixed
Результат mixed the removed value, null if no such key exists.

setReadOnly() защищенный Метод

protected setReadOnly ( $value )

toArray() публичный Метод

public toArray ( ) : array
Результат array the list of items in array