StaticProvider
extends AdhocProvider
in package
A static provider is useful for creating mock API implementations which manages records in-memory.
TODO Add a static provider to SyntaxConformanceTest to ensure that it's representative.
Table of Contents
Properties
- $actions : array<string|int, mixed>
- List of adhoc actions
- $entity : string
- $fields : mixed
- $records : mixed
- $version : int
Methods
- __construct() : mixed
- addAction() : AdhocProvider
- Register a new API.
- doCreate() : array<string|int, mixed>
- doDelete() : array<string|int, mixed>
- doGet() : array<string|int, mixed>
- getActionNames() : array<string|int, mixed>
- getEntityNames() : array<string|int, mixed>
- getRecords() : array<string|int, mixed>
- getSubscribedEvents() : array<string|int, mixed>
- invoke() : array<string|int, mixed>|mixed
- matchesRequest() : bool
- onApiAuthorize() : mixed
- onApiResolve() : mixed
- setRecords() : mixed
Properties
$actions
List of adhoc actions
protected
array<string|int, mixed>
$actions
= []
array(string $ame => array('perm' => string, 'callback' => callable))
$entity
protected
string
$entity
$fields
protected
mixed
$fields
$records
protected
mixed
$records
$version
protected
int
$version
Methods
__construct()
public
__construct(int $version, string $entity, array<string|int, mixed> $fields[, array<string|int, mixed> $perms = [] ][, array<string|int, mixed> $records = [] ]) : mixed
Parameters
- $version : int
-
API version.
- $entity : string
-
API entity.
- $fields : array<string|int, mixed>
-
List of fields in this fake entity.
- $perms : array<string|int, mixed> = []
-
Array(string $action => string $perm).
- $records : array<string|int, mixed> = []
-
List of mock records to be read/updated by API calls.
addAction()
Register a new API.
public
addAction(string $name, string $perm, mixed $callback) : AdhocProvider
Parameters
- $name : string
-
Action name.
- $perm : string
-
Permissions required for invoking the action.
- $callback : mixed
-
The function which executes the API.
Return values
AdhocProviderdoCreate()
public
doCreate(array<string|int, mixed> $apiRequest) : array<string|int, mixed>
Parameters
- $apiRequest : array<string|int, mixed>
-
The full description of the API request.
Tags
Return values
array<string|int, mixed> —Formatted API result
doDelete()
public
doDelete(array<string|int, mixed> $apiRequest) : array<string|int, mixed>
Parameters
- $apiRequest : array<string|int, mixed>
-
The full description of the API request.
Tags
Return values
array<string|int, mixed> —Formatted API result
doGet()
public
doGet(array<string|int, mixed> $apiRequest) : array<string|int, mixed>
Parameters
- $apiRequest : array<string|int, mixed>
-
The full description of the API request.
Tags
Return values
array<string|int, mixed> —Formatted API result
getActionNames()
public
getActionNames(int $version, string $entity) : array<string|int, mixed>
Parameters
- $version : int
- $entity : string
Tags
Return values
array<string|int, mixed>getEntityNames()
public
getEntityNames(int $version) : array<string|int, mixed>
Parameters
- $version : int
Tags
Return values
array<string|int, mixed>getRecords()
public
getRecords() : array<string|int, mixed>
Return values
array<string|int, mixed>getSubscribedEvents()
public
static getSubscribedEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>invoke()
public
invoke(array<string|int, mixed> $apiRequest) : array<string|int, mixed>|mixed
Parameters
- $apiRequest : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>|mixedmatchesRequest()
public
matchesRequest(array<string|int, mixed> $apiRequest) : bool
Parameters
- $apiRequest : array<string|int, mixed>
-
The full description of the API request.
Return values
boolonApiAuthorize()
public
onApiAuthorize(AuthorizeEvent $event) : mixed
Parameters
- $event : AuthorizeEvent
-
API authorization event.
onApiResolve()
public
onApiResolve(ResolveEvent $event) : mixed
Parameters
- $event : ResolveEvent
-
API resolution event.
setRecords()
public
setRecords(array<string|int, mixed> $records) : mixed
Parameters
- $records : array<string|int, mixed>
-
List of mock records to be read/updated by API calls.