Result
extends ArrayObject
in package
implements
JsonSerializable
Container for api results.
The Result object has three functions:
- Store the results of the API call (accessible via ArrayAccess).
- Store metadata like the Entity & Action names.
- Note: some actions extend the Result object to store extra metadata. For example, BasicReplaceAction returns ReplaceResult which includes the additional $deleted property to list any items deleted by the operation.
- Provide convenience methods like
$result->first()
and$result->indexBy($field)
.
Table of Contents
Interfaces
- JsonSerializable
Properties
- $action : string
- $debug : array<string|int, mixed>
- $entity : string
- $rowCount : int
- Not for public use. Instead, please use countFetched(), countMatched() and count().
- $version : int
- Api version
- $matchedCount : int
- How many entities matched the query, regardless of LIMIT clauses.
- $indexedBy : mixed
Methods
- column() : array<string|int, mixed>
- Reduce each result to one field
- count() : int
- Returns the number of results.
- countFetched() : int
- Returns the number of results fetched.
- countMatched() : int
- Returns the number of results
- first() : array<string|int, mixed>|null
- Return first result.
- indexBy() : $this
- Re-index the results array (which by default is non-associative)
- itemAt() : array<string|int, mixed>|null
- jsonSerialize() : array<string|int, mixed>
- last() : array<string|int, mixed>|null
- Return last result.
- rekey() : $this
- Rewrite keys in each result according to a map or a callback function.
- setCountMatched() : mixed
- Provides a way for API implementations to set the *matched* count.
- single() : array<string|int, mixed>
- Return the one-and-only result record.
Properties
$action
public
string
$action
$debug
public
array<string|int, mixed>
$debug
$entity
public
string
$entity
$rowCount
Not for public use. Instead, please use countFetched(), countMatched() and count().
public
int
$rowCount
$version
Api version
public
int
$version
= 4
$matchedCount
How many entities matched the query, regardless of LIMIT clauses.
protected
int
$matchedCount
This requires that row_count is included in the SELECT.
$indexedBy
private
mixed
$indexedBy
Methods
column()
Reduce each result to one field
public
column(string $columnName[, string|null $indexBy = NULL ]) : array<string|int, mixed>
Parameters
- $columnName : string
- $indexBy : string|null = NULL
Return values
array<string|int, mixed>count()
Returns the number of results.
public
count() : int
If row_count was included in the select fields, then this will be the number of matched entities, even if this differs from the number of entities fetched.
If row_count was not included, then this returns the number of entities fetched, which may or may not be the number of matches.
Your code might be easier to reason about if you use countFetched() or countMatched() instead.
Return values
intcountFetched()
Returns the number of results fetched.
public
countFetched() : int
If a limit was used, this will be a number up to that limit.
In the case that only the row_count was fetched, this will be zero, since no entities were fetched.
Return values
intcountMatched()
Returns the number of results
public
countMatched() : int
Return values
intfirst()
Return first result.
public
first() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullindexBy()
Re-index the results array (which by default is non-associative)
public
indexBy(string $key) : $this
Drops any item from the results that does not contain the specified key
Unlike $this->rekey, this rewrites the row keys not the column keys.
Parameters
- $key : string
Tags
Return values
$thisitemAt()
public
itemAt(int $index) : array<string|int, mixed>|null
Parameters
- $index : int
Return values
array<string|int, mixed>|nulljsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>last()
Return last result.
public
last() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullrekey()
Rewrite keys in each result according to a map or a callback function.
public
rekey(array<string|int, mixed>|callable $map) : $this
Unlike $this->indexBy, this rewrites the column keys not the row keys.
Parameters
- $map : array<string|int, mixed>|callable
-
Map of keys to convert e.g.
[old_key => new_key]
Or a callback function likefn($key, $value) => $newKey
Return values
$thissetCountMatched()
Provides a way for API implementations to set the *matched* count.
public
setCountMatched(int $c) : mixed
The matched count is the number of matching entities, regardless of any imposed limit clause.
Parameters
- $c : int
single()
Return the one-and-only result record.
public
single() : array<string|int, mixed>
If there are too many or too few results, then throw an exception.