AbstractCollection
This class provides a basic implementation of CollectionInterface
, to
minimize the effort required to implement this interface
- Full name:
\Ramsey\Collection\AbstractCollection
- Parent class:
\Ramsey\Collection\AbstractArray
- This class implements:
\Ramsey\Collection\CollectionInterface
- This class is an Abstract class
Methods
add
Ensures that this collection contains the specified element (optional operation).
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
mixed | The element to add to the collection. |
Return Value:
true
if this collection changed as a result of the call.
contains
Returns true
if this collection contains the specified element.
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
mixed | The element to check whether the collection contains. |
$strict |
bool | Whether to perform a strict type check on the value. |
offsetSet
Sets the given value to the given offset in the array.
Parameters:
Parameter | Type | Description |
---|---|---|
$offset |
mixed | The offset to set. If null , the value may beset at a numerically-indexed offset. |
$value |
mixed | The value to set at the given offset. |
remove
Removes a single instance of the specified element from this collection, if it is present.
Parameters:
Parameter | Type | Description |
---|---|---|
$element |
mixed | The element to remove from the collection. |
Return Value:
true
if an element was removed as a result of this call.
column
Returns the values from the given property or method.
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyOrMethod |
string | The property or method name to filter by. |
first
Returns the first item of the collection.
last
Returns the last item of the collection.
sort
Sort the collection by a property or method with the given sort order.
public sort(string $propertyOrMethod, string $order = self::SORT_ASC): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T>
This will always leave the original collection untouched and will return a new one.
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyOrMethod |
string | The property or method to sort by. |
$order |
string | The sort order for the resulting collection (one of this interface's SORT_* constants). |
filter
Filter out items of the collection which don't match the criteria of given callback.
public filter(callable $callback): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T>
This will always leave the original collection untouched and will return a new one.
See the {@link http://php.net/manual/en/function.array-filter.php}
for examples of how the $callback
parameter works.
Parameters:
Parameter | Type | Description |
---|---|---|
$callback |
callable | A callable to use for filtering elements. |
where
Create a new collection where items match the criteria of given callback.
public where(string $propertyOrMethod, mixed $value): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T>
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyOrMethod |
string | The property or method to evaluate. |
$value |
mixed | The value to match. |
map
Apply a given callback method on each item of the collection.
public map(callable $callback): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\TCallbackReturn>
This will always leave the original collection untouched. The new collection is created by mapping the callback to each item of the original collection.
See the {@link http://php.net/manual/en/function.array-map.php}
for examples of how the $callback
parameter works.
Parameters:
Parameter | Type | Description |
---|---|---|
$callback |
callable | A callable to apply to each item of the collection. |
diff
Create a new collection with divergent items between current and given collection.
public diff(\Ramsey\Collection\CollectionInterface $other): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T>
Parameters:
Parameter | Type | Description |
---|---|---|
$other |
\Ramsey\Collection\CollectionInterface | The collection to check for divergent items. |
intersect
Create a new collection with intersecting item between current and given collection.
public intersect(\Ramsey\Collection\CollectionInterface $other): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T>
Parameters:
Parameter | Type | Description |
---|---|---|
$other |
\Ramsey\Collection\CollectionInterface | The collection to check for intersecting items. |
merge
Merge current items and items of given collections into a new one.
public merge(\Ramsey\Collection\CollectionInterface $collections): \Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T>
Parameters:
Parameter | Type | Description |
---|---|---|
$collections |
\Ramsey\Collection\CollectionInterface | The collections to merge. |
unserialize
Converts a serialized string representation into an instance object.
Parameters:
Parameter | Type | Description |
---|---|---|
$serialized |
mixed | A PHP serialized string to unserialize. |
compareCollectionTypes
private compareCollectionTypes(\Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T> $other): void
Parameters:
Parameter | Type | Description |
---|---|---|
$other |
\Ramsey\Collection\CollectionInterface<\Ramsey\Collection\T> |
getComparator
Inherited methods
__construct
Constructs a new array object.
Parameters:
Parameter | Type | Description |
---|---|---|
$data |
array |
The initial items to add to this array. |
getIterator
Returns an iterator for this array.
See Also:
- http://php.net/manual/en/iteratoraggregate.getiterator.php - IteratorAggregate::getIterator()
offsetExists
Returns true
if the given offset exists in this array.
Parameters:
Parameter | Type | Description |
---|---|---|
$offset |
array-key | The offset to check. |
See Also:
- http://php.net/manual/en/arrayaccess.offsetexists.php - ArrayAccess::offsetExists()
offsetGet
Returns the value at the specified offset.
Parameters:
Parameter | Type | Description |
---|---|---|
$offset |
array-key | The offset for which a value should be returned. |
Return Value:
the value stored at the offset, or null if the offset does not exist.
See Also:
- http://php.net/manual/en/arrayaccess.offsetget.php - ArrayAccess::offsetGet()
offsetSet
Sets the given value to the given offset in the array.
Parameters:
Parameter | Type | Description |
---|---|---|
$offset |
(array-key)|null | The offset to set. If null , the value may beset at a numerically-indexed offset. |
$value |
\Ramsey\Collection\T | The value to set at the given offset. |
See Also:
- http://php.net/manual/en/arrayaccess.offsetset.php - ArrayAccess::offsetSet()
offsetUnset
Removes the given offset and its value from the array.
Parameters:
Parameter | Type | Description |
---|---|---|
$offset |
array-key | The offset to remove from the array. |
See Also:
- http://php.net/manual/en/arrayaccess.offsetunset.php - ArrayAccess::offsetUnset()
serialize
Returns a serialized string representation of this array object.
- Warning: this method is deprecated. This means that this method will likely be removed in a future version.
Return Value:
a PHP serialized string.
See Also:
- http://php.net/manual/en/serializable.serialize.php - Serializable::serialize()
__serialize
Returns data suitable for PHP serialization.
See Also:
- https://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.serialize - * https://www.php.net/serialize -
unserialize
Converts a serialized string representation into an instance object.
- Warning: this method is deprecated. This means that this method will likely be removed in a future version.
Parameters:
Parameter | Type | Description |
---|---|---|
$serialized |
string | A PHP serialized string to unserialize. |
See Also:
- http://php.net/manual/en/serializable.unserialize.php - Serializable::unserialize()
__unserialize
Adds unserialized data to the object.
Parameters:
Parameter | Type | Description |
---|---|---|
$data |
array |
count
Returns the number of items in this array.
See Also:
- http://php.net/manual/en/countable.count.php - Countable::count()
clear
Removes all items from this array.
toArray
Returns a native PHP array representation of this array object.
isEmpty
Returns true
if this array is empty.
extractValue
Extracts the value of the given property or method from the object.
Parameters:
Parameter | Type | Description |
---|---|---|
$object |
mixed | The object to extract the value from. |
$propertyOrMethod |
string | The property or method for which the value should be extracted. |
Return Value:
the value extracted from the specified property or method.
Throws:
if the method or property is not defined.
toolValueToString
Returns a string representation of the value.
- null value:
'NULL'
- boolean:
'TRUE'
,'FALSE'
- array:
'Array'
- scalar: converted-value
- resource:
'(type resource #number)'
- object with
__toString()
: result of__toString()
- object DateTime: ISO 8601 date
- object:
'(className Object)'
- anonymous function: same as object
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
mixed | the value to return as a string. |
checkType
Returns true
if value is of the specified type.
Parameters:
Parameter | Type | Description |
---|---|---|
$type |
string | The type to check the value against. |
$value |
mixed | The value to check. |
Automatically generated on 2025-03-18