AbstractSet
extends AbstractCollection
in package
This class contains the basic implementation of a collection that does not allow duplicated values (a set), to minimize the effort required to implement this specific type of collection.
Table of Contents
- $data : array<string|int, mixed>
- The items of this array.
- __construct() : mixed
- Constructs a new array object.
- add() : bool
- Adds the specified element to this set, if it is not already present.
- clear() : void
- Removes all items from this array.
- column() : array<string|int, mixed>
- Returns the values from given property or method.
- contains() : bool
- Returns `true` if this collection contains the specified element.
- count() : int
- Returns the number of items in this array.
- diff() : CollectionInterface<mixed, mixed>
- Create a new collection with divergent items between current and given collection.
- filter() : CollectionInterface<mixed, mixed>
- Returns a filtered collection.
- first() : mixed
- Returns the first item of the collection.
- getIterator() : ArrayIterator<mixed, mixed>
- Returns an iterator for this array.
- intersect() : CollectionInterface<mixed, mixed>
- Create a new collection with intersecting item between current and given collection.
- isEmpty() : bool
- Returns `true` if this array is empty.
- last() : mixed
- Returns the last item of the collection.
- map() : CollectionInterface<mixed, mixed>
- Applies a callback to each item of the collection.
- merge() : CollectionInterface<mixed, mixed>
- Merge current items and items of given collections into a new one.
- offsetExists() : bool
- Returns `true` if the given offset exists in this array.
- offsetGet() : mixed|null
- Returns the value at the specified offset.
- offsetSet() : void
- Sets the given value to the given offset in this set, if it is not already present.
- offsetUnset() : void
- Removes the given offset and its value from the array.
- remove() : bool
- Removes a single instance of the specified element from this collection, if it is present.
- serialize() : string
- Returns a serialized string representation of this array object.
- sort() : CollectionInterface<mixed, mixed>
- Returns a sorted collection.
- toArray() : array<string|int, mixed>
- Returns a native PHP array representation of this array object.
- unserialize() : void
- Converts a serialized string representation into an instance object.
- where() : CollectionInterface<mixed, mixed>
- Returns a collection of matching items.
- checkType() : bool
- Returns `true` if value is of the specified type.
- extractValue() : mixed
- Extracts the value of the given property or method from the object.
- toolValueToString() : string
- Returns a string representation of the value.
Properties
$data
The items of this array.
protected
array<string|int, mixed>
$data
= []
Methods
__construct()
Constructs a new array object.
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
-
The initial items to add to this array.
Return values
mixed —add()
Adds the specified element to this set, if it is not already present.
public
add(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to the set.
Tags
Return values
bool —true
if this set did not already contain the specified
element.
clear()
Removes all items from this array.
public
clear() : void
Return values
void —column()
Returns the values from given property or method.
public
column(string $propertyOrMethod) : array<string|int, mixed>
Parameters
- $propertyOrMethod : string
-
The property or method name to filter by.
Tags
Return values
array<string|int, mixed> —contains()
Returns `true` if this collection contains the specified element.
public
contains(mixed $element[, bool $strict = true ]) : bool
Parameters
- $element : mixed
-
The element to check whether the collection contains.
- $strict : bool = true
-
Whether to perform a strict type check on the value.
Return values
bool —count()
Returns the number of items in this array.
public
count() : int
Tags
Return values
int —diff()
Create a new collection with divergent items between current and given collection.
public
diff(CollectionInterface<mixed, mixed> $other) : CollectionInterface<mixed, mixed>
Parameters
- $other : CollectionInterface<mixed, mixed>
-
The collection to check for divergent items.
Tags
Return values
CollectionInterface<mixed, mixed> —filter()
Returns a filtered collection.
public
filter(callable $callback) : CollectionInterface<mixed, mixed>
Parameters
- $callback : callable
-
A callable to use for filtering elements.
Return values
CollectionInterface<mixed, mixed> —first()
Returns the first item of the collection.
public
first() : mixed
Tags
Return values
mixed —getIterator()
Returns an iterator for this array.
public
getIterator() : ArrayIterator<mixed, mixed>
Tags
Return values
ArrayIterator<mixed, mixed> —intersect()
Create a new collection with intersecting item between current and given collection.
public
intersect(CollectionInterface<mixed, mixed> $other) : CollectionInterface<mixed, mixed>
Parameters
- $other : CollectionInterface<mixed, mixed>
-
The collection to check for intersecting items.
Tags
Return values
CollectionInterface<mixed, mixed> —isEmpty()
Returns `true` if this array is empty.
public
isEmpty() : bool
Return values
bool —last()
Returns the last item of the collection.
public
last() : mixed
Tags
Return values
mixed —map()
Applies a callback to each item of the collection.
public
map(callable $callback) : CollectionInterface<mixed, mixed>
Parameters
- $callback : callable
-
A callable to apply to each item of the collection.
Return values
CollectionInterface<mixed, mixed> —merge()
Merge current items and items of given collections into a new one.
public
merge(CollectionInterface<mixed, mixed> ...$collections) : CollectionInterface<mixed, mixed>
Parameters
- $collections : CollectionInterface<mixed, mixed>
-
The collections to merge.
Tags
Return values
CollectionInterface<mixed, mixed> —offsetExists()
Returns `true` if the given offset exists in this array.
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
The offset to check.
Tags
Return values
bool —offsetGet()
Returns the value at the specified offset.
public
offsetGet(mixed $offset) : mixed|null
Parameters
- $offset : mixed
-
The offset for which a value should be returned.
Tags
Return values
mixed|null —the value stored at the offset, or null if the offset does not exist.
offsetSet()
Sets the given value to the given offset in this set, if it is not already present.
public
offsetSet(mixed|null $offset, mixed $value) : void
Parameters
- $offset : mixed|null
-
The offset is ignored and is treated as
null
. - $value : mixed
-
The value to set at the given offset.
Tags
Return values
void —offsetUnset()
Removes the given offset and its value from the array.
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
-
The offset to remove from the array.
Tags
Return values
void —remove()
Removes a single instance of the specified element from this collection, if it is present.
public
remove(mixed $element) : bool
Parameters
- $element : mixed
-
The element to remove from the collection.
Return values
bool —true
if an element was removed as a result of this call.
serialize()
Returns a serialized string representation of this array object.
public
serialize() : string
Tags
Return values
string —a PHP serialized string.
sort()
Returns a sorted collection.
public
sort(string $propertyOrMethod[, string $order = self::SORT_ASC ]) : CollectionInterface<mixed, mixed>
Parameters
- $propertyOrMethod : string
-
The property or method to sort by.
- $order : string = self::SORT_ASC
-
The sort order for the resulting collection (one of this interface's
SORT_*
constants).
Tags
Return values
CollectionInterface<mixed, mixed> —toArray()
Returns a native PHP array representation of this array object.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —unserialize()
Converts a serialized string representation into an instance object.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
-
A PHP serialized string to unserialize.
Tags
Return values
void —where()
Returns a collection of matching items.
public
where(string $propertyOrMethod, mixed $value) : CollectionInterface<mixed, mixed>
Parameters
- $propertyOrMethod : string
-
The property or method to evaluate.
- $value : mixed
-
The value to match.
Tags
Return values
CollectionInterface<mixed, mixed> —checkType()
Returns `true` if value is of the specified type.
protected
checkType(string $type, mixed $value) : bool
Parameters
- $type : string
-
The type to check the value against.
- $value : mixed
-
The value to check.
Return values
bool —extractValue()
Extracts the value of the given property or method from the object.
protected
extractValue(object $object, string $propertyOrMethod) : mixed
Parameters
- $object : object
-
The object to extract the value from.
- $propertyOrMethod : string
-
The property or method for which the value should be extracted.
Tags
Return values
mixed —the value extracted from the specified property or method.
toolValueToString()
Returns a string representation of the value.
protected
toolValueToString(mixed $value) : string
- 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
- $value : mixed
-
the value to return as a string.