Class \Prado\Collections\TList
TList implements an integer-indexed collection class.
You can access, append, insert, remove an item by using itemAt, add, insertAt, remove, and removeAt. To get the number of the items in the list, use getCount. TList can also be used like a regular array as follows,
$list[]=$item; // append at the end
$list[$index]=$item; // $index must be between 0 and $list->Count
unset($list[$index]); // remove the item at $index
if(isset($list[$index])) // if the list has an item at $index
foreach($list as $index=>$item) // traverse each item in the list
$n=count($list); // returns the number of items in the list
To extend TList by doing additional operations with each addition or removal operation, override insertAt(), and removeAt().
Class hierarchy
- \Prado\Collections\TList implements IteratorAggregate, ArrayAccess, Countable
- \Prado\TComponent
Since: 3.0
public
|
__construct([null|array<string|int, mixed>|Iterator $data = null ][, bool|null $readOnly = null ]) : mixed
Constructor.
Initializes the list with an array or an iterable object. |
public
|
|
public
|
|
public
|
|
public
|
copyFrom(mixed $data) : void
Copies iterable data into the list.
Note, existing data in the list will be cleared first. |
public
|
count() : int
Returns the number of items in the list.
This method is required by \Countable interface. |
public
|
|
public
|
getIterator() : Iterator
Returns an iterator for traversing the items in the list.
This method is required by the interface \IteratorAggregate. |
public
|
|
public
|
|
public
|
insertAfter(mixed $baseitem, mixed $item) : int
Finds the base item. If found, the item is inserted after it.
|
public
|
insertAt(int $index, mixed $item) : mixed
Inserts an item at the specified position.
Original item at the position and the next items will be moved one step towards the end. |
public
|
insertBefore(mixed $baseitem, mixed $item) : int
Finds the base item. If found, the item is inserted before it.
|
public
|
itemAt(int $index) : mixed
Returns the item at the specified offset.
This method is exactly the same as offsetGet. |
public
|
mergeWith(mixed $data) : void
Merges iterable data into the map.
New data will be appended to the end of the existing data. |
public
|
offsetExists(int $offset) : bool
Returns whether there is an item at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetGet(int $offset) : mixed
Returns the item at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetSet(int $offset, mixed $item) : void
Sets the item at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetUnset(int $offset) : void
Unsets the item at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
remove(mixed $item) : int
Removes an item from the list.
The list will first search for the item. The first item found will be removed from the list. |
public
|
|
public
|
|
public
|
|
protected
|
_getZappableSleepProps(array<string|int, mixed> &$exprops) : mixed
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.
When there are no items in the list, _d and _c are not stored |
protected
|
\Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |