ResultSet
in package
implements
ResultSetInterface
uses
CollectionTrait
Represents the results obtained after executing a query for a specific table This object is responsible for correctly nesting result keys reported from the query, casting each field to the correct type and executing the extra queries required for eager loading external associations.
Table of Contents
Interfaces
- ResultSetInterface
- Describes how a collection of datasource results should look like
Properties
- $_autoFields : bool|null
- Tracks value of $_autoFields property of $query passed to constructor.
- $_containMap : array<string|int, mixed>
- List of associations that should be eager loaded.
- $_count : int
- Holds the count of records in this result set
- $_current : object|array<string|int, mixed>
- Last record fetched from the statement
- $_defaultAlias : string
- The default table alias
- $_defaultTable : Table
- Default table instance
- $_driver : DriverInterface
- The Database driver object.
- $_entityClass : string
- The fully namespaced name of the class to use for hydrating results
- $_hydrate : bool
- Whether to hydrate results into objects or not
- $_index : int
- Points to the next record number that should be fetched
- $_map : array<string, mixed>
- Map of fields that are fetched from the statement with their type and the table they belong to
- $_matchingMap : array<string, mixed>
- List of associations that should be placed under the `_matchingData` result key.
- $_matchingMapColumns : array<string, mixed>
- List of matching associations and the column keys to expect from each of them.
- $_results : SplFixedArray|array<string|int, mixed>
- Results that have been fetched or hydrated into the results.
- $_statement : StatementInterface
- Database statement holding the results
- $_useBuffering : bool
- Whether to buffer results fetched from the statement
Methods
- __construct() : mixed
- Constructor
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __serialize() : array<string|int, mixed>
- Serializes a resultset.
- __unserialize() : void
- Unserializes a resultset.
- append() : CollectionInterface
- appendItem() : CollectionInterface
- avg() : mixed
- buffered() : CollectionInterface
- cartesianProduct() : CollectionInterface
- {@inheritDoc}
- chunk() : CollectionInterface
- chunkWithKeys() : CollectionInterface
- combine() : CollectionInterface
- compile() : CollectionInterface
- contains() : bool
- count() : int
- Gives the number of rows in the result set.
- countBy() : CollectionInterface
- countKeys() : int
- current() : object|array<string|int, mixed>
- Returns the current record in the result iterator
- each() : mixed
- every() : bool
- extract() : CollectionInterface
- filter() : CollectionInterface
- first() : object|array<string|int, mixed>|null
- Get the first record from a result set.
- firstMatch() : mixed
- groupBy() : CollectionInterface
- indexBy() : CollectionInterface
- insert() : CollectionInterface
- isEmpty() : bool
- jsonSerialize() : array<string|int, mixed>
- key() : int
- Returns the key of the current record in the iterator
- last() : mixed
- lazy() : CollectionInterface
- listNested() : CollectionInterface
- map() : CollectionInterface
- match() : CollectionInterface
- max() : mixed
- median() : mixed
- min() : mixed
- nest() : CollectionInterface
- next() : void
- Advances the iterator pointer to the next record
- prepend() : CollectionInterface
- prependItem() : CollectionInterface
- reduce() : mixed
- reject() : CollectionInterface
- rewind() : void
- Rewinds a ResultSet.
- sample() : CollectionInterface
- serialize() : string
- Serializes a resultset.
- shuffle() : CollectionInterface
- skip() : CollectionInterface
- some() : bool
- sortBy() : CollectionInterface
- stopWhen() : CollectionInterface
- sumOf() : mixed
- take() : CollectionInterface
- takeLast() : CollectionInterface
- through() : CollectionInterface
- toArray() : array<string|int, mixed>
- toList() : array<string|int, mixed>
- transpose() : CollectionInterface
- {@inheritDoc}
- unfold() : CollectionInterface
- unserialize() : void
- Unserializes a resultset.
- unwrap() : Traversable
- valid() : bool
- Whether there are more results to be fetched from the iterator
- zip() : CollectionInterface
- zipWith() : CollectionInterface
- _calculateAssociationMap() : void
- Calculates the list of associations that should get eager loaded when fetching each record
- _calculateColumnMap() : void
- Creates a map of row keys out of the query select clause that can be used to hydrate nested result sets more quickly.
- _fetchResult() : mixed
- Helper function to fetch the next result from the statement or seeded results.
- _groupResult() : EntityInterface|array<string|int, mixed>
- Correctly nests results keys including those coming from associations
- newCollection() : CollectionInterface
- Returns a new collection.
- optimizeUnwrap() : iterable<string|int, mixed>
- Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Properties
$_autoFields
Tracks value of $_autoFields property of $query passed to constructor.
protected
bool|null
$_autoFields
$_containMap
List of associations that should be eager loaded.
protected
array<string|int, mixed>
$_containMap
= []
$_count
Holds the count of records in this result set
protected
int
$_count
$_current
Last record fetched from the statement
protected
object|array<string|int, mixed>
$_current
$_defaultAlias
The default table alias
protected
string
$_defaultAlias
$_defaultTable
Default table instance
protected
Table
$_defaultTable
$_driver
The Database driver object.
protected
DriverInterface
$_driver
Cached in a property to avoid multiple calls to the same function.
$_entityClass
The fully namespaced name of the class to use for hydrating results
protected
string
$_entityClass
$_hydrate
Whether to hydrate results into objects or not
protected
bool
$_hydrate
= true
$_index
Points to the next record number that should be fetched
protected
int
$_index
= 0
$_map
Map of fields that are fetched from the statement with their type and the table they belong to
protected
array<string, mixed>
$_map
= []
$_matchingMap
List of associations that should be placed under the `_matchingData` result key.
protected
array<string, mixed>
$_matchingMap
= []
$_matchingMapColumns
List of matching associations and the column keys to expect from each of them.
protected
array<string, mixed>
$_matchingMapColumns
= []
$_results
Results that have been fetched or hydrated into the results.
protected
SplFixedArray|array<string|int, mixed>
$_results
= []
$_statement
Database statement holding the results
protected
StatementInterface
$_statement
$_useBuffering
Whether to buffer results fetched from the statement
protected
bool
$_useBuffering
= true
Methods
__construct()
Constructor
public
__construct(Query $query, StatementInterface $statement) : mixed
Parameters
- $query : Query
-
Query from where results come
- $statement : StatementInterface
-
The statement to fetch from
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__serialize()
Serializes a resultset.
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__unserialize()
Unserializes a resultset.
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
-
Data array.
append()
public
append(mixed $items) : CollectionInterface
Parameters
- $items : mixed
Tags
Return values
CollectionInterfaceappendItem()
public
appendItem(mixed $item[, mixed $key = null ]) : CollectionInterface
Parameters
- $item : mixed
- $key : mixed = null
Tags
Return values
CollectionInterfaceavg()
public
avg([mixed $path = null ]) : mixed
Parameters
- $path : mixed = null
Tags
buffered()
public
buffered() : CollectionInterface
Tags
Return values
CollectionInterfacecartesianProduct()
{@inheritDoc}
public
cartesianProduct([callable|null $operation = null ][, callable|null $filter = null ]) : CollectionInterface
Parameters
- $operation : callable|null = null
-
A callable that allows you to customize the product result.
- $filter : callable|null = null
-
A filtering callback that must return true for a result to be part of the final results.
Tags
Return values
CollectionInterfacechunk()
public
chunk(int $chunkSize) : CollectionInterface
Parameters
- $chunkSize : int
Tags
Return values
CollectionInterfacechunkWithKeys()
public
chunkWithKeys(int $chunkSize[, bool $keepKeys = true ]) : CollectionInterface
Parameters
- $chunkSize : int
- $keepKeys : bool = true
Tags
Return values
CollectionInterfacecombine()
public
combine(mixed $keyPath, mixed $valuePath[, mixed $groupPath = null ]) : CollectionInterface
Parameters
- $keyPath : mixed
- $valuePath : mixed
- $groupPath : mixed = null
Tags
Return values
CollectionInterfacecompile()
public
compile([bool $keepKeys = true ]) : CollectionInterface
Parameters
- $keepKeys : bool = true
Tags
Return values
CollectionInterfacecontains()
public
contains(mixed $value) : bool
Parameters
- $value : mixed
Tags
Return values
boolcount()
Gives the number of rows in the result set.
public
count() : int
Part of the Countable interface.
Return values
intcountBy()
public
countBy(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfacecountKeys()
public
countKeys() : int
Tags
Return values
intcurrent()
Returns the current record in the result iterator
public
current() : object|array<string|int, mixed>
Part of Iterator interface.
Attributes
- #[ReturnTypeWillChange]
Return values
object|array<string|int, mixed>each()
public
each(callable $callback) : mixed
Parameters
- $callback : callable
Tags
every()
public
every(callable $callback) : bool
Parameters
- $callback : callable
Tags
Return values
boolextract()
public
extract(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfacefilter()
public
filter([callable|null $callback = null ]) : CollectionInterface
Parameters
- $callback : callable|null = null
Tags
Return values
CollectionInterfacefirst()
Get the first record from a result set.
public
first() : object|array<string|int, mixed>|null
This method will also close the underlying statement cursor.
Return values
object|array<string|int, mixed>|nullfirstMatch()
public
firstMatch(array<string|int, mixed> $conditions) : mixed
Parameters
- $conditions : array<string|int, mixed>
Tags
groupBy()
public
groupBy(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfaceindexBy()
public
indexBy(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfaceinsert()
public
insert(string $path, mixed $values) : CollectionInterface
Parameters
- $path : string
- $values : mixed
Tags
Return values
CollectionInterfaceisEmpty()
public
isEmpty() : bool
Tags
Return values
booljsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>key()
Returns the key of the current record in the iterator
public
key() : int
Part of Iterator interface.
Return values
intlast()
public
last() : mixed
Tags
lazy()
public
lazy() : CollectionInterface
Tags
Return values
CollectionInterfacelistNested()
public
listNested([mixed $order = 'desc' ][, mixed $nestingKey = 'children' ]) : CollectionInterface
Parameters
- $order : mixed = 'desc'
- $nestingKey : mixed = 'children'
Tags
Return values
CollectionInterfacemap()
public
map(callable $callback) : CollectionInterface
Parameters
- $callback : callable
Tags
Return values
CollectionInterfacematch()
public
match(array<string|int, mixed> $conditions) : CollectionInterface
Parameters
- $conditions : array<string|int, mixed>
Tags
Return values
CollectionInterfacemax()
public
max(mixed $path[, int $sort = SORT_NUMERIC ]) : mixed
Parameters
- $path : mixed
- $sort : int = SORT_NUMERIC
Tags
median()
public
median([mixed $path = null ]) : mixed
Parameters
- $path : mixed = null
Tags
min()
public
min(mixed $path[, int $sort = SORT_NUMERIC ]) : mixed
Parameters
- $path : mixed
- $sort : int = SORT_NUMERIC
Tags
nest()
public
nest(mixed $idPath, mixed $parentPath[, string $nestingKey = 'children' ]) : CollectionInterface
Parameters
- $idPath : mixed
- $parentPath : mixed
- $nestingKey : string = 'children'
Tags
Return values
CollectionInterfacenext()
Advances the iterator pointer to the next record
public
next() : void
Part of Iterator interface.
prepend()
public
prepend(mixed $items) : CollectionInterface
Parameters
- $items : mixed
Tags
Return values
CollectionInterfaceprependItem()
public
prependItem(mixed $item[, mixed $key = null ]) : CollectionInterface
Parameters
- $item : mixed
- $key : mixed = null
Tags
Return values
CollectionInterfacereduce()
public
reduce(callable $callback[, mixed $initial = null ]) : mixed
Parameters
- $callback : callable
- $initial : mixed = null
Tags
reject()
public
reject(callable $callback) : CollectionInterface
Parameters
- $callback : callable
Tags
Return values
CollectionInterfacerewind()
Rewinds a ResultSet.
public
rewind() : void
Part of Iterator interface.
Tags
sample()
public
sample([int $length = 10 ]) : CollectionInterface
Parameters
- $length : int = 10
Tags
Return values
CollectionInterfaceserialize()
Serializes a resultset.
public
serialize() : string
Part of Serializable interface.
Return values
string —Serialized object
shuffle()
public
shuffle() : CollectionInterface
Tags
Return values
CollectionInterfaceskip()
public
skip(int $length) : CollectionInterface
Parameters
- $length : int
Tags
Return values
CollectionInterfacesome()
public
some(callable $callback) : bool
Parameters
- $callback : callable
Tags
Return values
boolsortBy()
public
sortBy(mixed $path[, int $order = SORT_DESC ][, int $sort = SORT_NUMERIC ]) : CollectionInterface
Parameters
- $path : mixed
- $order : int = SORT_DESC
- $sort : int = SORT_NUMERIC
Tags
Return values
CollectionInterfacestopWhen()
public
stopWhen(mixed $condition) : CollectionInterface
Parameters
- $condition : mixed
Tags
Return values
CollectionInterfacesumOf()
public
sumOf([mixed $path = null ]) : mixed
Parameters
- $path : mixed = null
Tags
take()
public
take([int $length = 1 ][, int $offset = 0 ]) : CollectionInterface
Parameters
- $length : int = 1
- $offset : int = 0
Tags
Return values
CollectionInterfacetakeLast()
public
takeLast(int $length) : CollectionInterface
Parameters
- $length : int
Tags
Return values
CollectionInterfacethrough()
public
through(callable $callback) : CollectionInterface
Parameters
- $callback : callable
Tags
Return values
CollectionInterfacetoArray()
public
toArray([bool $keepKeys = true ]) : array<string|int, mixed>
Parameters
- $keepKeys : bool = true
Tags
Return values
array<string|int, mixed>toList()
public
toList() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>transpose()
{@inheritDoc}
public
transpose() : CollectionInterface
Tags
Return values
CollectionInterfaceunfold()
public
unfold([callable|null $callback = null ]) : CollectionInterface
Parameters
- $callback : callable|null = null
Tags
Return values
CollectionInterfaceunserialize()
Unserializes a resultset.
public
unserialize(string $serialized) : void
Part of Serializable interface.
Parameters
- $serialized : string
-
Serialized object
unwrap()
public
unwrap() : Traversable
Tags
Return values
Traversablevalid()
Whether there are more results to be fetched from the iterator
public
valid() : bool
Part of Iterator interface.
Return values
boolzip()
public
zip(iterable<string|int, mixed> $items) : CollectionInterface
Parameters
- $items : iterable<string|int, mixed>
Tags
Return values
CollectionInterfacezipWith()
public
zipWith(iterable<string|int, mixed> $items, mixed $callback) : CollectionInterface
Parameters
- $items : iterable<string|int, mixed>
- $callback : mixed
Tags
Return values
CollectionInterface_calculateAssociationMap()
Calculates the list of associations that should get eager loaded when fetching each record
protected
_calculateAssociationMap(Query $query) : void
Parameters
- $query : Query
-
The query from where to derive the associations
_calculateColumnMap()
Creates a map of row keys out of the query select clause that can be used to hydrate nested result sets more quickly.
protected
_calculateColumnMap(Query $query) : void
Parameters
- $query : Query
-
The query from where to derive the column map
_fetchResult()
Helper function to fetch the next result from the statement or seeded results.
protected
_fetchResult() : mixed
_groupResult()
Correctly nests results keys including those coming from associations
protected
_groupResult(array<string|int, mixed> $row) : EntityInterface|array<string|int, mixed>
Parameters
- $row : array<string|int, mixed>
-
Array containing columns and values or false if there is no results
Return values
EntityInterface|array<string|int, mixed> —Results
newCollection()
Returns a new collection.
protected
newCollection(mixed ...$args) : CollectionInterface
Allows classes which use this trait to determine their own type of returned collection interface
Parameters
- $args : mixed
-
Constructor arguments.
Return values
CollectionInterfaceoptimizeUnwrap()
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
protected
optimizeUnwrap() : iterable<string|int, mixed>