class WhitelistRule

A WhitelistRule is used to determine if an API call is authorized.

For example:

Properties

static $IGNORE_FIELDS
int $version
string $entity Entity name or '*' (all entities)
string|array $actions List of actions which match, or '*' (all actions)
array $required List of key=>value pairs that must appear in $params.
array $fields List of fields which may be optionally inputted or returned, or '*" (all fields)

Methods

static array
createAll(array $rules)

Create a batch of rules from an array.

__construct($ruleSpec)

No description

bool
isValid()

No description

string|TRUE
matches(array $apiRequest)

No description

array
filter(array $apiRequest, array $apiResult)

Ensure that the return values comply with the whitelist's "fields" policy.

array
filterFields(array $keys)

Determine which elements in $keys are acceptable under the whitelist policy.

Details

at line 72
static array createAll(array $rules)

Create a batch of rules from an array.

Parameters

array $rules

Return Value

array

at line 115
__construct($ruleSpec)

Parameters

$ruleSpec

at line 142
bool isValid()

Return Value

bool

at line 167
string|TRUE matches(array $apiRequest)

Parameters

array $apiRequest Parsed API request.

Return Value

string|TRUE If match, return TRUE. Otherwise, return a string with an error code.

at line 241
array filter(array $apiRequest, array $apiResult)

Ensure that the return values comply with the whitelist's "fields" policy.

Most API's follow a convention where the result includes a 'values' array (which in turn is a list of records). Unfortunately, some don't. If the API result doesn't meet our expectation, then we probably don't know what's going on, so we abort the request.

This will probably break some of the layered-sugar APIs (like getsingle, getvalue). Just use the meat-and-potatoes API instead. Or craft a suitably targeted patch.

Parameters

array $apiRequest API request.
array $apiResult API result.

Return Value

array Modified API result.

Exceptions

API_Exception

at line 269
protected array filterFields(array $keys)

Determine which elements in $keys are acceptable under the whitelist policy.

Parameters

array $keys List of possible keys.

Return Value

array List of acceptable keys.