ContainerQuery
in package
Class ContainerQuery
Container query is a helper class to filter, sort, etc. the values of the container hierarchy.
Tags
Table of Contents
- $container : BaseContainer
- $desc : bool
- $filters : array<string|int, mixed>
- $pluck : string|null
- $sortClosure : Closure
- $sorter : BaseSorter
- $sortProperty : string
- $topLevelOnly : bool
- $uniqueOnly : bool
- __construct() : mixed
- ContainerQuery constructor.
- addSorter() : $this
- desc() : $this
- Sort in descending order
- filter() : $this
- Add a filter callback
- get() : array<string|int, mixed>
- Get the result
- getFirst() : mixed|null
- Gets the first result of container query
- ids() : $this
- Get only the object's ids
- only() : ContainerQuery
- Pluck a specific key from all values
- sort() : $this
- Sort a result using a callback - maintaining the index association
- sortBy() : $this
- Sort a result set by a given property
- unique() : $this
- Get only unique values
- whereId() : ContainerQuery
- Filter results to only contain those with a specific ID
- applyFilters() : void
- Apply predefined filters on data
- filterUnique() : void
- Filter data to contain only unique values
- pluckData() : void
- Pluck a predefined value from data values
- sortByPropertyCallback() : int
- Sort function for sorting by a defined property
- sortData() : void
- Sort data using a predefined filters
Properties
$container
protected
BaseContainer
$container
$desc
protected
bool
$desc
= false
$filters
protected
array<string|int, mixed>
$filters
= []
$pluck
protected
string|null
$pluck
= null
$sortClosure
protected
Closure
$sortClosure
$sorter
protected
BaseSorter
$sorter
$sortProperty
protected
string
$sortProperty
$topLevelOnly
protected
bool
$topLevelOnly
= false
$uniqueOnly
protected
bool
$uniqueOnly
= false
Methods
__construct()
ContainerQuery constructor.
public
__construct(BaseContainer $container[, bool $topLevelOnly = false ]) : mixed
Parameters
- $container : BaseContainer
-
Queried container
- $topLevelOnly : bool = false
Return values
mixed —addSorter()
public
addSorter(BaseSorter $sorter) : $this
Parameters
- $sorter : BaseSorter
Return values
$this —desc()
Sort in descending order
public
desc() : $this
Return values
$this —filter()
Add a filter callback
public
filter(Closure $callback) : $this
Parameters
- $callback : Closure
Return values
$this —get()
Get the result
public
get() : array<string|int, mixed>
Return values
array<string|int, mixed> —getFirst()
Gets the first result of container query
public
getFirst() : mixed|null
Return values
mixed|null —ids()
Get only the object's ids
public
ids() : $this
Tags
Return values
$this —only()
Pluck a specific key from all values
public
only(string $property) : ContainerQuery
Parameters
- $property : string
-
Property, array key or method to extract from values
Tags
Return values
ContainerQuery —sort()
Sort a result using a callback - maintaining the index association
public
sort(Closure $callback) : $this
Parameters
- $callback : Closure
Return values
$this —sortBy()
Sort a result set by a given property
public
sortBy(string $property) : $this
Parameters
- $property : string
Tags
Return values
$this —unique()
Get only unique values
public
unique() : $this
Return values
$this —whereId()
Filter results to only contain those with a specific ID
public
whereId(string|int $id) : ContainerQuery
Parameters
- $id : string|int
Return values
ContainerQuery —applyFilters()
Apply predefined filters on data
protected
applyFilters( &$data) : void
Parameters
Return values
void —filterUnique()
Filter data to contain only unique values
protected
filterUnique(array<string|int, mixed> &$data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —pluckData()
Pluck a predefined value from data values
protected
pluckData( &$data) : void
Parameters
Return values
void —sortByPropertyCallback()
Sort function for sorting by a defined property
protected
sortByPropertyCallback(array<string|int, mixed>|object $value1, array<string|int, mixed>|object $value2) : int
Parameters
- $value1 : array<string|int, mixed>|object
- $value2 : array<string|int, mixed>|object
Return values
int —sortData()
Sort data using a predefined filters
protected
sortData(array<string|int, mixed> &$data) : void
Parameters
- $data : array<string|int, mixed>