PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TMap

TMap class

TMap implements a collection that takes key-value pairs.

You can access, add or remove an item with a key by using TMap::itemAt(), TMap::add(), and TMap::remove(). To get the number of the items in the map, use TMap::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
TComponent
Extended by TMap implements IteratorAggregate, ArrayAccess, Countable

Direct known subclasses

TAttributeCollection, TPriorityMap
Package: System\Collections
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Collections/TMap.php
Methods summary
public
# __construct( array|Iterator $data = null, boolean $readOnly = false )

Constructor. Initializes the list with an array or an iterable object.

Constructor. Initializes the list with an array or an iterable object.

Parameters

$data
array|Iterator
the intial data. Default is null, meaning no initialization.
$readOnly
boolean
whether the list is read-only

Throws

TInvalidDataTypeException
If data is not null and neither an array nor an iterator.

Overrides

TComponent::__construct()
public boolean
# getReadOnly( )

Returns

boolean
whether this map is read-only or not. Defaults to false.
protected
# setReadOnly( boolean $value )

Parameters

$value
boolean
whether this list is read-only or not
public Iterator
# getIterator( )

Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.

Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.

Returns

Iterator
an iterator for traversing the items in the list.

Implementation of

IteratorAggregate::getIterator()
public integer
# count( )

Returns the number of items in the map. This method is required by Countable interface.

Returns the number of items in the map. This method is required by Countable interface.

Returns

integer
number of items in the map.

Implementation of

Countable::count()
public integer
# getCount( )

Returns

integer
the number of items in the map
public array
# getKeys( )

Returns

array
the key list
public mixed
# itemAt( mixed $key )

Returns the item with the specified key. This method is exactly the same as TMap::offsetGet().

Returns the item with the specified key. This method is exactly the same as TMap::offsetGet().

Parameters

$key
mixed
the key

Returns

mixed
the element at the offset, null if no element is found at the offset
public
# add( mixed $key, mixed $value )

Adds an item into the map. Note, if the specified key already exists, the old value will be overwritten.

Adds an item into the map. Note, if the specified key already exists, the old value will be overwritten.

Parameters

$key
mixed
key
$value
mixed
value

Throws

TInvalidOperationException
if the map is read-only
public mixed
# remove( mixed $key )

Removes an item from the map by its key.

Removes an item from the map by its key.

Parameters

$key
mixed
the key of the item to be removed

Returns

mixed
the removed value, null if no such key exists.

Throws

TInvalidOperationException
if the map is read-only
public
# clear( )

Removes all items in the map.

Removes all items in the map.

public boolean
# contains( mixed $key )

Parameters

$key
mixed
the key

Returns

boolean
whether the map contains an item with the specified key
public array
# toArray( )

Returns

array
the list of items in array
public
# copyFrom( mixed $data )

Copies iterable data into the map. Note, existing data in the map will be cleared first.

Copies iterable data into the map. Note, existing data in the map will be cleared first.

Parameters

$data
mixed
the data to be copied from, must be an array or object implementing Traversable

Throws

TInvalidDataTypeException
If data is neither an array nor an iterator.
public
# mergeWith( mixed $data )

Merges iterable data into the map. Existing data in the map will be kept and overwritten if the keys are the same.

Merges iterable data into the map. Existing data in the map will be kept and overwritten if the keys are the same.

Parameters

$data
mixed
the data to be merged with, must be an array or object implementing Traversable

Throws

TInvalidDataTypeException
If data is neither an array nor an iterator.
public boolean
# offsetExists( mixed $offset )

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to check on

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( integer $offset )

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
integer
the offset to retrieve element.

Returns

mixed
the element at the offset, null if no element is found at the offset

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( integer $offset, mixed $item )

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
integer
the offset to set element
$item
mixed
the element value

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $offset )

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to unset element

Implementation of

ArrayAccess::offsetUnset()
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO