System
[ class tree: System ] [ index: System ] [ all elements ]

Class: TCollection

Source Location: /classes.php

Class Overview


TCollection class

Class Details

[line 251]
TCollection class

TCollection implements basic collection functionalities. It requires SPL support of PHP 5. You can use a TCollection object like an array with cardinal indexes starting from 0. For example,

  1. $collection=new TCollection;
  2. $collection[]='item 1';
  3. $collection[]='item 2';
  4. unset($collection[0]);
Note, if you unset any element in the collection, the rest elements will be re-indexed. It is recommended you use TCollection in OO fashion, i.e.,
  1. $collection=new TCollection;
  2. $collection->add('item 1');
  3. $collection->addAt(0,'item 2');
  4. $collection->removeAt(0);
  5. $collection->clear();
You can use a TCollection object in foreach() like following,
  1. foreach($collection as $item)
  2. { }
Note, to get the number of items in a collection, use $collection->length(). Calling count($collection) will always return 1.




version:  v1.0, last update on 2005/01/17 21:44:52
author:  Qiang Xue <qiang.xue@gmail.com>


[ Top ]

Variables

Methods


Child classes:

TBodyCollection
TBodyCollection class.
TDataGridItemCollection
TDataGridItemCollection class
TDataListItemCollection
TCollection class

Class Variables

$data = array()

[line 257]

internal data storage



access:  protected

Type:   array


[ Top ]

$readOnly = false

[line 262]

whether this collection allows addition/removal of elements



access:  protected

Type:   boolean


[ Top ]



Class Methods


constructor __construct [line 269]

TCollection __construct( [mixed $data = null], [boolean $readOnly = false])

Constructor.



access:  public


Overridden in child classes as:

TBodyCollection::__construct()
Constructor.
TDataGridItemCollection::__construct()
Constructor.
TDataListItemCollection::__construct()

Parameters:

mixed   $data   initial collection data
boolean   $readOnly   whether the collection is read-only

[ Top ]

method add [line 404]

void add( mixed $item)

Appends an item at the end of the collection.



access:  public


Parameters:

mixed   $item   new item

[ Top ]

method addAt [line 416]

void addAt( integer $index, mixed $item)

Inserts an item at the specified position.

Original item at the position and the next items will be moved one step towards the end.




access:  public


Parameters:

integer   $index   the speicified position.
mixed   $item   new item

[ Top ]

method clear [line 437]

void clear( )

Removes all items in the collection.



access:  public


[ Top ]

method contains [line 479]

boolean contains( mixed $item)



return:  whether the collection contains the item
access:  public


Parameters:

mixed   $item   the item

[ Top ]

method current [line 303]

mixed current( )

Returns the current array element.

This method should only be used by framework and component developers.




return:  the current array element
access:  public


[ Top ]

method getArray [line 517]

array getArray( )



return:  array representation of the data in the collection
access:  public


[ Top ]

method indexOf [line 488]

integer indexOf( mixed $item)



return:  the index of the item in the collection, -1 if not found.
access:  public


Parameters:

mixed   $item   the item

[ Top ]

method isReadOnly [line 395]

boolean isReadOnly( )



return:  whether this collection allows addition/removal of elements.
access:  public


[ Top ]

method key [line 293]

integer key( )

Returns the key of the current array element.

This method should only be used by framework and component developers.




return:  the key of the current array element
access:  public


[ Top ]

method length [line 387]

integer length( )



return:  the number of elements in the collection
access:  public


[ Top ]

method next [line 312]

void next( )

Moves the internal pointer to the next array element.

This method should only be used by framework and component developers.




access:  public


[ Top ]

method offsetExists [line 333]

boolean offsetExists( integer $offset)

Returns whether there is an element at the specified offset.

This method should only be used by framework and component developers.




access:  public


Parameters:

integer   $offset   the offset to check on

[ Top ]

method offsetGet [line 344]

mixed offsetGet( integer $offset)

Returns the element at the specified offset.

This method should only be used by framework and component developers.




access:  public


Parameters:

integer   $offset   the offset to retrieve element.

[ Top ]

method offsetSet [line 356]

void offsetSet( mixed $offset, mixed $item)

Required by interface.

Do not call this method.




access:  public


[ Top ]

method offsetUnset [line 376]

void offsetUnset( mixed $offset)

Required by interface.

Do not call this method.




access:  public


[ Top ]

method onAddItem [line 501]

boolean onAddItem( mixed $item)

This method will be invoked when an item is being added to the collection.



return:  whether the item should be added.
access:  protected


Overridden in child classes as:

TBodyCollection::onAddItem()
Checks if an item can be added into body collection.
TDataGridItemCollection::onAddItem()
Adds TDataGridItem object to the body collection.
TDataListItemCollection::onAddItem()

Parameters:

mixed   $item   the item to be added.

[ Top ]

method onRemoveItem [line 510]

void onRemoveItem( mixed $item)

This method will be invoked when an item is being removed from the collection.



access:  protected


Overridden in child classes as:

TDataGridItemCollection::onRemoveItem()
Removes the item from the body collection.
TDataListItemCollection::onRemoveItem()

Parameters:

mixed   $item   the item to be removed.

[ Top ]

method remove [line 452]

void remove( mixed $item)

Removes an item from the collection.

The collection will first search for the item. The first item found will be removed from the collection.




access:  public


Parameters:

mixed   $item   the item to be removed.

[ Top ]

method removeAt [line 462]

void removeAt( integer $index)

Removes an item at the specified position.



access:  public


Parameters:

integer   $index   the index of the item to be removed.

[ Top ]

method rewind [line 283]

void rewind( )

Rewinds internal array pointer.

This method should only be used by framework and component developers.




access:  public


[ Top ]

method valid [line 322]

boolean valid( )

Returns whether there is an element at current position.

This method should only be used by framework and component developers.




access:  public


[ Top ]


© 2004-2005 PRADO Software Group. All Rights Reserved.