Tournament Generator

ContainerQuery

Class ContainerQuery

Container query is a helper class to filter, sort, etc. the values of the container hierarchy.

Tags
author

Tomáš Vojík vojik@wboy.cz

since
0.4

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

Methods

__construct()

ContainerQuery constructor.

public __construct(BaseContainer $container[, bool $topLevelOnly = false ]) : mixed
Parameters
$container : BaseContainer

Queried container

$topLevelOnly : bool = false
Return values
mixed

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
throws
Exception
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
throws
Exception
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
warning

Sort callback has a priority.

Return values
$this

unique()

Get only unique values

public unique() : $this
Return values
$this

applyFilters()

Apply predefined filters on data

protected applyFilters( &$data) : void
Parameters
$data :
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
$data :
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>
Return values
void

Search results