CollectionBaseDto
extends ArrayObject
in package
implements
Arrayable
PHP Mini Framework
Tags
Interfaces, Classes, Traits and Enums
- Arrayable
- PHP Mini Framework
Table of Contents
- ITEM_CLASS = NULL
- Define the class that will be used for all items in the array.
- __clone() : mixed
- Clone a collection by cloning all items.
- at() : mixed
- Returns the item in the collection at $index.
- chunk() : ArrayObject
- Chunks the object into ArrayObject containing
- column() : array<string|int, mixed>
- each() : mixed
- Applies the callback function $callable to each item in the collection.
- filter() : static
- Filtering the array by retrieving only these elements for which callback returns true
- find() : mixed
- Finding the first element in the Array, for which $callback returns true
- first() : mixed
- Reset the array pointer to the first element and return the element.
- indexExists() : bool
- Returns true if $index is within the collection's range and returns false if it is not.
- insert() : mixed
- Inserting the provided element at the index. If index is negative, it will be calculated from the end of the Array Object
- keys() : array<string|int, mixed>
- last() : mixed
- Reset the array pointer to the last element and return the element.
- load() : self
- Load data
- map() : ArrayObject
- of() : static
- Load dto with array
- reduce() : mixed
- Use a user supplied callback to reduce the array to a single member and return it.
- reverse() : static
- Apply a user supplied function to every member of an array
- slice() : static
- Extract a slice of the array.
- sort() : bool
- Sort an array.
- splice() : static
- Remove a portion of the array and optionally replace it with something else.
- toArray() : array<string|int, mixed>
- Get array response data
- unshift() : int
- Adding a new value at the beginning of the collection
- walk() : bool
- Apply a user supplied function to every member of an array
- __construct() : mixed
- Constructor
- validateIndex() : mixed
- Validates a number to be used as an index
Constants
ITEM_CLASS
Define the class that will be used for all items in the array.
public
mixed
ITEM_CLASS
= NULL
To be defined in each sub-class.
Tags
Methods
__clone()
Clone a collection by cloning all items.
public
__clone() : mixed
Tags
Return values
mixed —at()
Returns the item in the collection at $index.
public
at(int $index) : mixed
Parameters
- $index : int
Tags
Return values
mixed —chunk()
Chunks the object into ArrayObject containing
public
chunk(int $size[, bool $preserveKeys = false ]) : ArrayObject
Parameters
- $size : int
- $preserveKeys : bool = false
Tags
Return values
ArrayObject —column()
public
column(mixed $columnKey) : array<string|int, mixed>
Parameters
- $columnKey : mixed
Tags
Return values
array<string|int, mixed> —each()
Applies the callback function $callable to each item in the collection.
public
each(callable $callable) : mixed
Parameters
- $callable : callable
Tags
Return values
mixed —filter()
Filtering the array by retrieving only these elements for which callback returns true
public
filter(callable $callback[, int $flag = 0 ]) : static
Parameters
- $callback : callable
- $flag : int = 0
-
Use ARRAY_FILTER_USE_KEY to pass key as the only argument to $callback instead of value. Use ARRAY_FILTER_USE_BOTH pass both value and key as arguments to $callback instead of value.
Tags
Return values
static —find()
Finding the first element in the Array, for which $callback returns true
public
find(callable $callback) : mixed
Parameters
- $callback : callable
Tags
Return values
mixed —Element Found in the Array or null
first()
Reset the array pointer to the first element and return the element.
public
first() : mixed
Tags
Return values
mixed —indexExists()
Returns true if $index is within the collection's range and returns false if it is not.
public
indexExists(int $index) : bool
Parameters
- $index : int
Tags
Return values
bool —insert()
Inserting the provided element at the index. If index is negative, it will be calculated from the end of the Array Object
public
insert(int $index, mixed $element) : mixed
Parameters
- $index : int
- $element : mixed
Tags
Return values
mixed —keys()
public
keys() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —last()
Reset the array pointer to the last element and return the element.
public
last() : mixed
Tags
Return values
mixed —load()
Load data
public
load(array<string|int, mixed>|Traversable $data) : self
Parameters
- $data : array<string|int, mixed>|Traversable
Tags
Return values
self —map()
public
map(callable $mapper) : ArrayObject
Parameters
- $mapper : callable
-
Will be called as $mapper(mixed $item)
Tags
Return values
ArrayObject —A collection of the results of $mapper(mixed $item)
of()
Load dto with array
public
static of(array<string|int, mixed>|object $data) : static
Parameters
- $data : array<string|int, mixed>|object
Tags
Return values
static —reduce()
Use a user supplied callback to reduce the array to a single member and return it.
public
reduce(callable $callback[, mixed|null $initial = null ]) : mixed
Parameters
- $callback : callable
- $initial : mixed|null = null
Tags
Return values
mixed —reverse()
Apply a user supplied function to every member of an array
public
reverse([bool $preserveKeys = false ]) : static
Parameters
- $preserveKeys : bool = false
Tags
Return values
static —slice()
Extract a slice of the array.
public
slice(int $offset[, int|null $length = null ][, bool $preserveKeys = false ]) : static
Parameters
- $offset : int
- $length : int|null = null
- $preserveKeys : bool = false
Tags
Return values
static —sort()
Sort an array.
public
sort([int $sortFlags = SORT_REGULAR ]) : bool
Parameters
- $sortFlags : int = SORT_REGULAR
Tags
Return values
bool —splice()
Remove a portion of the array and optionally replace it with something else.
public
splice(int $offset[, int|null $length = null ][, null $replacement = null ]) : static
Parameters
- $offset : int
- $length : int|null = null
- $replacement : null = null
Tags
Return values
static —toArray()
Get array response data
public
toArray([bool $trim = true ]) : array<string|int, mixed>
Parameters
- $trim : bool = true
-
Remove NULL properties
Tags
Return values
array<string|int, mixed> —unshift()
Adding a new value at the beginning of the collection
public
unshift(mixed $value) : int
Parameters
- $value : mixed
Tags
Return values
int —Returns the new number of elements in the Array
walk()
Apply a user supplied function to every member of an array
public
walk(callable $callback[, mixed|null $userData = null ]) : bool
Parameters
- $callback : callable
- $userData : mixed|null = null
Tags
Return values
bool —Returns true on success, otherwise false
__construct()
Constructor
protected
__construct([array<string|int, mixed>|object $input = [] ][, int $flags = 0 ][, string $iteratorClass = ArrayIterator::class ]) : mixed
Store the required array type prior to parental construction.
Parameters
- $input : array<string|int, mixed>|object = []
-
Any data to preset the array to.
- $flags : int = 0
-
The flags to control the behaviour of the ArrayObject.
- $iteratorClass : string = ArrayIterator::class
-
Specify the class that will be used for iteration of the ArrayObject object. ArrayIterator is the default class used.
Tags
Return values
mixed —validateIndex()
Validates a number to be used as an index
private
validateIndex(int $index) : mixed
Parameters
- $index : int
-
The number to be validated as an index