class GetActions extends BasicGetAction

Get actions for an entity with a list of accepted params

Traits

Helper functions for performing api queries on arrays of data.

Properties

protected int $version Api version number; cannot be changed. from AbstractAction
protected array $chain Additional api requests - will be called once per result. from AbstractAction
protected bool $checkPermissions Whether to enforce acl permissions based on the current user. from AbstractAction
protected string $_entityName from AbstractAction
protected string $_actionName from AbstractAction
protected array $where Criteria for selecting items. from AbstractQueryAction
protected array $orderBy Array of field(s) to use in ordering the results from AbstractQueryAction
protected int $limit Maximum number of results to return. from AbstractQueryAction
protected int $offset Zero-based index of first result to return. from AbstractQueryAction
protected array $select Fields to return. Defaults to all fields. from AbstractGetAction

Methods

__construct(string $entityName, string $actionName, callable $getter = NULL)

Basic Get constructor.

__set($name, $value)

Strictly enforce api parameters

$this
setVersion(int $val)

No description

$this
addChain(string $name, AbstractAction $apiRequest, string|int $index = NULL)

No description

__call($name, $arguments)

Magic function to provide addFoo, getFoo and setFoo for params.

execute()

Invoke api call.

_run(Result $result)

Fetch results from the getter then apply filter/sort/select/limit.

array
getParams()

Serialize this object's params into an array

array
getParamInfo(string $param = NULL)

Get documentation for one or all params

string
getEntityName()

No description

string
getActionName()

No description

bool
paramExists(string $param)

No description

array
getParamDefaults()

No description

offsetExists($offset)

No description

offsetGet($offset)

No description

offsetSet($offset, $value)

No description

offsetUnset($offset)

No description

bool
isAuthorized()

Is this api call permitted?

array
getPermissions()

No description

array
entityFields()

Returns schema fields for this entity & action.

reflect()

No description

array
checkRequiredFields($values)

Validates required fields for actions which create a new object.

bool
evaluateCondition(string $expr, array $vars)

This function is used internally for evaluating field annotations.

bool
getCheckPermissions()

No description

array
getChain()

No description

$this
addWhere(string $field, string $op, mixed $value = NULL)

No description

$this
addClause(string $operator, mixed $condition1)

Adds one or more AND/OR/NOT clause groups

$this
addOrderBy(string $field, string $direction = 'ASC')

No description

string
whereClauseToString(array $whereClause = NULL, string $op = 'AND')

A human-readable where clause, for the reading enjoyment of you humans.

array
getWhere()

No description

array
getOrderBy()

No description

int
getLimit()

No description

int
getOffset()

No description

$this
selectRowCount()

Only return the number of found items.

setDefaultWhereClause()

Adds field defaults to the where clause.

array|null
_itemsToGet(string $field)

Helper to parse the WHERE param for getRecords to perform simple pre-filtering.

bool
_isFieldSelected(string $field)

Helper to see if a field should be selected by the getRecords function.

bool
_whereContains(string $field, array $clauses = NULL)

Walk through the where clause and check if a field is in use.

array
getSelect()

No description

array
queryArray(array $values)

No description

array
filterArray(array $values)

No description

array
sortArray($values)

No description

array
selectArray($values)

No description

array
limitArray($values)

No description

array
getRecords()

This Basic Get class is a general-purpose api for non-DAO-based entities.

fields()

No description

Details

in BasicGetAction at line 64
__construct(string $entityName, string $actionName, callable $getter = NULL)

Basic Get constructor.

Parameters

string $entityName
string $actionName
callable $getter

in AbstractAction at line 149
__set($name, $value)

Strictly enforce api parameters

Parameters

$name
$value

Exceptions

Exception

in AbstractAction at line 158
$this setVersion(int $val)

Parameters

int $val

Return Value

$this

Exceptions

API_Exception

in AbstractAction at line 174
$this addChain(string $name, AbstractAction $apiRequest, string|int $index = NULL)

Parameters

string $name Unique name for this chained request
AbstractAction $apiRequest
string|int $index Either a string for how the results should be indexed e.g. 'name' or the index of a single result to return e.g. 0 for the first result.

Return Value

$this

in AbstractAction at line 187
AbstractAction|mixed __call($name, $arguments)

Magic function to provide addFoo, getFoo and setFoo for params.

Parameters

$name
$arguments

Return Value

AbstractAction|mixed

Exceptions

API_Exception

in AbstractAction at line 231
Result execute()

Invoke api call.

At this point all the params have been sent in and we initiate the api call & return the result. This is basically the outer wrapper for api v4.

Return Value

Result

Exceptions

UnauthorizedException

in BasicGetAction at line 74
_run(Result $result)

Fetch results from the getter then apply filter/sort/select/limit.

Parameters

Result $result

in AbstractAction at line 247
array getParams()

Serialize this object's params into an array

Return Value

array

in AbstractAction at line 265
array getParamInfo(string $param = NULL)

Get documentation for one or all params

Parameters

string $param

Return Value

array of arrays [description, type, default, (comment)]

in AbstractAction at line 282
string getEntityName()

Return Value

string

in AbstractAction at line 290
string getActionName()

Return Value

string

in AbstractAction at line 298
bool paramExists(string $param)

Parameters

string $param

Return Value

bool

in AbstractAction at line 305
protected array getParamDefaults()

Return Value

array

in AbstractAction at line 312
offsetExists($offset)

Parameters

$offset

in AbstractAction at line 319
offsetGet($offset)

Parameters

$offset

in AbstractAction at line 344
offsetSet($offset, $value)

Parameters

$offset
$value

in AbstractAction at line 359
offsetUnset($offset)

Parameters

$offset

in AbstractAction at line 373
bool isAuthorized()

Is this api call permitted?

This function is called if checkPermissions is set to true.

Return Value

bool

in AbstractAction at line 381
array getPermissions()

Return Value

array

in AbstractAction at line 410
array entityFields()

Returns schema fields for this entity & action.

Here we bypass the api wrapper and execute the getFields action directly. This is because we DON'T want the wrapper to check permissions as this is an internal op, but we DO want permissions to be checked inside the getFields request so e.g. the api_key field can be conditionally included.

Return Value

array

See also

GetFields

in AbstractAction at line 429
ReflectionClass reflect()

Return Value

ReflectionClass

in AbstractAction at line 443
protected array checkRequiredFields($values)

Validates required fields for actions which create a new object.

Parameters

$values

Return Value

array

Exceptions

API_Exception

in AbstractAction at line 473
protected bool evaluateCondition(string $expr, array $vars)

This function is used internally for evaluating field annotations.

It should never be passed raw user input.

Parameters

string $expr Conditional in php format e.g. $foo > $bar
array $vars Variable name => value

Return Value

bool

Exceptions

API_Exception
Exception

in AbstractAction at line 50
bool getCheckPermissions()

Return Value

bool

in AbstractAction at line 50
array getChain()

Return Value

array

in AbstractQueryAction at line 104
$this addWhere(string $field, string $op, mixed $value = NULL)

Parameters

string $field
string $op
mixed $value

Return Value

$this

Exceptions

API_Exception

in AbstractQueryAction at line 122
$this addClause(string $operator, mixed $condition1)

Adds one or more AND/OR/NOT clause groups

Parameters

string $operator
mixed $condition1 ... $conditionN Either a nested array of arguments, or a variable number of arguments passed to this function.

Return Value

$this

Exceptions

API_Exception

in AbstractQueryAction at line 135
$this addOrderBy(string $field, string $direction = 'ASC')

Parameters

string $field
string $direction

Return Value

$this

in AbstractQueryAction at line 147
protected string whereClauseToString(array $whereClause = NULL, string $op = 'AND')

A human-readable where clause, for the reading enjoyment of you humans.

Parameters

array $whereClause
string $op

Return Value

string

in AbstractQueryAction at line 54
array getWhere()

Return Value

array

in AbstractQueryAction at line 54
array getOrderBy()

Return Value

array

in AbstractQueryAction at line 54
int getLimit()

Return Value

int

in AbstractQueryAction at line 54
int getOffset()

Return Value

int

in AbstractGetAction at line 65
$this selectRowCount()

Only return the number of found items.

Return Value

$this

in AbstractGetAction at line 78
protected setDefaultWhereClause()

Adds field defaults to the where clause.

Note: it will skip adding field defaults when fetching records by id, or if that field has already been added to the where clause.

Exceptions

API_Exception

in AbstractGetAction at line 102
protected array|null _itemsToGet(string $field)

Helper to parse the WHERE param for getRecords to perform simple pre-filtering.

This is intended to optimize some common use-cases e.g. calling the api to get one or more records by name or id.

Ex: If getRecords fetches a long list of items each with a unique name, but the user has specified a single record to retrieve, you can optimize the call by checking $this->_itemsToGet('name') and only fetching the item(s) with that name.

Parameters

string $field

Return Value

array|null

in AbstractGetAction at line 123
protected bool _isFieldSelected(string $field)

Helper to see if a field should be selected by the getRecords function.

Checks the SELECT, WHERE and ORDER BY params to see what fields are needed.

Note that if no SELECT clause has been set then all fields should be selected and this function will always return TRUE.

Parameters

string $field

Return Value

bool

in AbstractGetAction at line 137
protected bool _whereContains(string $field, array $clauses = NULL)

Walk through the where clause and check if a field is in use.

Parameters

string $field
array $clauses

Return Value

bool

in AbstractGetAction at line 49
array getSelect()

Return Value

array

in ArrayQueryActionTrait at line 55
protected array queryArray(array $values)

Parameters

array $values List of all rows

Return Value

array Filtered list of rows

in ArrayQueryActionTrait at line 67
protected array filterArray(array $values)

Parameters

array $values

Return Value

array

in ArrayQueryActionTrait at line 186
protected array sortArray($values)

Parameters

$values

Return Value

array

in ArrayQueryActionTrait at line 213
protected array selectArray($values)

Parameters

$values

Return Value

array

in ArrayQueryActionTrait at line 229
protected array limitArray($values)

Parameters

$values

Return Value

array

at line 54
protected array getRecords()

This Basic Get class is a general-purpose api for non-DAO-based entities.

Useful for fetching records from files or other places. You can specify any php function to retrieve the records, and this class will automatically filter, sort, select & limit the raw data from your callback.

You can implement this action in one of two ways: 1. Use this class directly by passing a callable ($getter) to the constructor. 2. Extend this class and override this function.

Either way, this function should return an array of arrays, each representing one retrieved object.

The simplest thing for your getter function to do is return every full record and allow this class to automatically do the sorting and filtering.

Sometimes however that may not be practical for performance reasons. To optimize your getter, it can use the following helpers from $this:

Use this->_itemsToGet() to match records to field values in the WHERE clause. Note the WHERE clause can potentially be very complex and it is not recommended to parse $this->where yourself.

Use $this->_isFieldSelected() to check if a field value is called for - useful if loading the field involves expensive calculations.

Be careful not to make assumptions, e.g. if LIMIT 100 is specified and your getter "helpfully" truncates the list at 100 without accounting for WHERE, ORDER BY and LIMIT clauses, the final filtered result may be very incorrect.

Return Value

array

Exceptions

NotImplementedException

at line 127
fields()