Doctrine


Doctrine\Common\Collections\Collection
/Doctrine/Common/Collections/Collection.php at line 51

Interface Collection

Class:Collection - Superclass: Countable
Countable
⌊ Collection

public interface Collection
extends Countable

The missing (SPL) Collection/Array/OrderedMap interface.

A Collection resembles the nature of a regular PHP array. That is, it is essentially an ordered map that can also be used like a list.

A Collection has an internal iterator just like a PHP array. In addition, a Collection can be iterated with external iterators, which is preferrable. To use an external iterator simply use the foreach language construct to iterate over the collection (which calls getIterator() internally) or explicitly retrieve an iterator though getIterator() which can then be used to iterate over the collection. You can not rely on the internal iterator of the collection being at a certain position unless you explicitly positioned it before. Prefer iteration with external iterators.

License:
http://www.opensource.org/licenses/lgpl-license.php LGPL
See Also:
www.doctrine-project.org
Since:
2.0
Version:
$Revision: 3938 $
Author:
Guilherme Blanco
Jonathan Wage
Roman Borschel

Method Summary
boolean

add(mixed element)

Adds an element at the end of the collection.

void

clear()

Clears the collection, removing all elements.

boolean

contains(mixed element)

Checks whether an element is contained in the collection.

boolean

containsKey(string|integer key)

Checks whether the collection contains an element with the specified key/index.

void

current()

Gets the element of the collection at the current iterator position.

boolean

exists(Closure p)

Tests for the existence of an element that satisfies the given predicate.

Collection

filter(Closure p)

Returns all the elements of this collection that satisfy the predicate p.

mixed

first()

Sets the internal iterator to the first element in the collection and returns this element.

boolean

forAll(Closure p)

Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements.

mixed

get(string|integer key)

Gets the element at the specified key/index.

array

getKeys()

Gets all keys/indices of the collection.

array

getValues()

Gets all values of the collection.

mixed

indexOf(mixed element)

Gets the index/key of a given element.

boolean

isEmpty()

Checks whether the collection is empty (contains no elements).

void

key()

Gets the key/index of the element at the current iterator position.

mixed

last()

Sets the internal iterator to the last element in the collection and returns this element.

Collection

map(Closure func)

Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.

void

next()

Moves the internal iterator position to the next element.

array

partition(Closure p)

Partitions this collection in two collections according to a predicate.

mixed

remove(string|integer key)

Removes the element at the specified index from the collection.

mixed

removeElement(mixed element)

Removes an element from the collection.

void

set(string|integer key, mixed value)

Sets an element in the collection at the specified key/index.

array

toArray()

Gets a native PHP array representation of the collection.

Method Detail

/Doctrine/Common/Collections/Collection.php at line 59

add

public boolean add(mixed element)

Adds an element at the end of the collection.

Parameters:
element - The element to add.
Returns:
Always TRUE.

/Doctrine/Common/Collections/Collection.php at line 64

clear

public void clear()

Clears the collection, removing all elements.


/Doctrine/Common/Collections/Collection.php at line 73

contains

public boolean contains(mixed element)

Checks whether an element is contained in the collection. This is an O(n) operation, where n is the size of the collection.

Parameters:
element - The element to search for.
Returns:
TRUE if the collection contains the element, FALSE otherwise.

/Doctrine/Common/Collections/Collection.php at line 105

containsKey

public boolean containsKey(string|integer key)

Checks whether the collection contains an element with the specified key/index.

Parameters:
key - The key/index to check for.
Returns:
TRUE if the collection contains an element with the specified key/index, FALSE otherwise.

/Doctrine/Common/Collections/Collection.php at line 172

current

public void current()

Gets the element of the collection at the current iterator position.


/Doctrine/Common/Collections/Collection.php at line 186

exists

public boolean exists(Closure p)

Tests for the existence of an element that satisfies the given predicate.

Parameters:
p - The predicate.
Returns:
TRUE if the predicate is TRUE for at least one element, FALSE otherwise.

/Doctrine/Common/Collections/Collection.php at line 195

filter

public Collection filter(Closure p)

Returns all the elements of this collection that satisfy the predicate p. The order of the elements is preserved.

Parameters:
p - The predicate used for filtering.
Returns:
A collection with the results of the filter operation.

/Doctrine/Common/Collections/Collection.php at line 152

first

public mixed first()

Sets the internal iterator to the first element in the collection and returns this element.


/Doctrine/Common/Collections/Collection.php at line 204

forAll

public boolean forAll(Closure p)

Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements.

Parameters:
p - The predicate.
Returns:
TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.

/Doctrine/Common/Collections/Collection.php at line 113

get

public mixed get(string|integer key)

Gets the element at the specified key/index.

Parameters:
key - The key/index of the element to retrieve.

/Doctrine/Common/Collections/Collection.php at line 121

getKeys

public array getKeys()

Gets all keys/indices of the collection.

Returns:
The keys/indices of the collection, in the order of the corresponding elements in the collection.

/Doctrine/Common/Collections/Collection.php at line 129

getValues

public array getValues()

Gets all values of the collection.

Returns:
The values of all elements in the collection, in the order they appear in the collection.

/Doctrine/Common/Collections/Collection.php at line 234

indexOf

public mixed indexOf(mixed element)

Gets the index/key of a given element. The comparison of two elements is strict, that means not only the value but also the type must match. For objects this means reference equality.

Parameters:
element - The element to search for.
Returns:
The key/index of the element or FALSE if the element was not found.

/Doctrine/Common/Collections/Collection.php at line 80

isEmpty

public boolean isEmpty()

Checks whether the collection is empty (contains no elements).

Returns:
TRUE if the collection is empty, FALSE otherwise.

/Doctrine/Common/Collections/Collection.php at line 166

key

public void key()

Gets the key/index of the element at the current iterator position.


/Doctrine/Common/Collections/Collection.php at line 160

last

public mixed last()

Sets the internal iterator to the last element in the collection and returns this element.


/Doctrine/Common/Collections/Collection.php at line 213

map

public Collection map(Closure func)

Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.


/Doctrine/Common/Collections/Collection.php at line 178

next

public void next()

Moves the internal iterator position to the next element.


/Doctrine/Common/Collections/Collection.php at line 224

partition

public array partition(Closure p)

Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections.

Parameters:
p - The predicate on which to partition.
Returns:
An array with two elements. The first element contains the collection of elements where the predicate returned TRUE, the second element contains the collection of elements where the predicate returned FALSE.

/Doctrine/Common/Collections/Collection.php at line 88

remove

public mixed remove(string|integer key)

Removes the element at the specified index from the collection.

Parameters:
key - The kex/index of the element to remove.
Returns:
The removed element or NULL, if the collection did not contain the element.

/Doctrine/Common/Collections/Collection.php at line 96

removeElement

public mixed removeElement(mixed element)

Removes an element from the collection.

Parameters:
element - The element to remove.
Returns:
The removed element or NULL, if the collection did not contain the element.

/Doctrine/Common/Collections/Collection.php at line 137

set

public void set(string|integer key, mixed value)

Sets an element in the collection at the specified key/index.

Parameters:
key - The key/index of the element to set.
value - The element to set.

/Doctrine/Common/Collections/Collection.php at line 144

toArray

public array toArray()

Gets a native PHP array representation of the collection.


Doctrine