AbstractCollection
abstract class AbstractCollection extends AbstractArray implements CollectionInterface (View source)
This class provides a basic implementation of CollectionInterface
, to
minimize the effort required to implement this interface
Traits
Properties
protected array | $data | The items of this array. | from AbstractArray |
Methods
Returns true
if the given offset exists in this array.
Sets the given value to the given offset in the array.
Removes the given offset and its value from the array.
Returns a serialized string representation of this array object.
Converts a serialized string representation into an instance object.
Returns true
if value is of the specified type.
Returns a string representation of the value.
Extracts the value of the given property or method from the object.
Ensures that this collection contains the specified element.
Returns true
if this collection contains the specified element.
Removes a single instance of the specified element from this collection, if it is present.
Returns the values from given property or method.
Returns the first item of the collection.
Returns the last item of the collection.
Returns a sorted collection.
Returns a filtered collection.
Returns a collection of matching items.
Applies a callback to each item of the collection.
Create a new collection with divergent items between current and given collection.
Create a new collection with intersecting item between current and given collection.
Merge current items and items of given collections into a new one.
Details
in AbstractArray at line 35
__construct(array $data = [])
Constructs a new array object.
in AbstractArray at line 51
Traversable
getIterator()
Returns an iterator for this array.
in AbstractArray at line 65
bool
offsetExists(mixed $offset)
Returns true
if the given offset exists in this array.
in AbstractArray at line 80
mixed|null
offsetGet(mixed $offset)
Returns the value at the specified offset.
at line 75
void
offsetSet(mixed|null $offset, mixed $value)
Sets the given value to the given offset in the array.
in AbstractArray at line 110
void
offsetUnset(mixed $offset)
Removes the given offset and its value from the array.
in AbstractArray at line 122
string
serialize()
Returns a serialized string representation of this array object.
at line 336
void
unserialize(string $serialized)
Converts a serialized string representation into an instance object.
in AbstractArray at line 146
int
count()
Returns the number of items in this array.
in AbstractArray at line 154
void
clear()
Removes all items from this array.
in AbstractArray at line 164
array
toArray()
Returns a native PHP array representation of this array object.
in AbstractArray at line 174
bool
isEmpty()
Returns true
if this array is empty.
protected bool
checkType(string $type, mixed $value)
Returns true
if value is of the specified type.
in ValueToStringTrait at line 38
protected string
toolValueToString(mixed $value)
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
in ValueExtractorTrait at line 35
protected mixed
extractValue(object $object, string $propertyOrMethod)
Extracts the value of the given property or method from the object.
at line 46
bool
add(mixed $element)
Ensures that this collection contains the specified element.
at line 61
bool
contains(mixed $element, bool $strict = true)
Returns true
if this collection contains the specified element.
at line 95
bool
remove(mixed $element)
Removes a single instance of the specified element from this collection, if it is present.
at line 115
array
column(string $propertyOrMethod)
Returns the values from given property or method.
at line 133
mixed
first()
Returns the first item of the collection.
at line 151
mixed
last()
Returns the last item of the collection.
at line 178
CollectionInterface
sort(string $propertyOrMethod, string $order = self::SORT_ASC)
Returns a sorted collection.
{@inheritdoc}
at line 205
CollectionInterface
filter(callable $callback)
Returns a filtered collection.
{@inheritdoc}
at line 225
CollectionInterface
where(string $propertyOrMethod, mixed $value)
Returns a collection of matching items.
{@inheritdoc}
at line 244
CollectionInterface
map(callable $callback)
Applies a callback to each item of the collection.
{@inheritdoc}
at line 264
CollectionInterface
diff(CollectionInterface $other)
Create a new collection with divergent items between current and given collection.
at line 292
CollectionInterface
intersect(CollectionInterface $other)
Create a new collection with intersecting item between current and given collection.
at line 314
CollectionInterface
merge(CollectionInterface ...$collections)
Merge current items and items of given collections into a new one.