ResourceBase
extends ProcessorEntity
in package
Class ResourceBase
Base class for all resource processors.
Table of Contents
- $id : mixed
- Processor ID.
- $db : ADOConnection|null
- DB connections.
- $details : array<string|int, mixed>
- {@inheritDoc}
- $helper : ProcessorHelper
- Processor helper class.
- $logger : MonologWrapper
- Logger object.
- $meta : array<string|int, mixed>
- Metadata for the processor.
- $request : Request
- All the request details.
- $accountMapper : AccountMapper
- Account mapper class.
- $settings : Config
- Config class.
- __construct() : mixed
- details() : array<string|int, mixed>
- Return details for processor.
- process() : DataContainer
- {@inheritDoc}
- val() : mixed|DataContainer
- Process a variable into a final result for the processor.
- create() : DataContainer
- Create or update a resource from input data into the caller's app and acc.
- delete() : DataContainer
- Delete a resource.
- exportData() : mixed
- Abstract class used to fetch input resource into the correct array format.
- generateParams() : array<string|int, mixed>
- Generate the params array for the sql search.
- importData() : mixed
- Abstract class used to fetch input resource into the correct array format.
- isDataContainer() : bool
- Validate if a set of data is wrapped in a DataContainer object.
- read() : DataContainer
- Fetch a resource.
- validateCoreProtection() : mixed
- Validate application is not core and core not locked.
- validateData() : void
- Validate input data is well formed.
- identicalIds() : void
- Search for identical IDs.
- validateAllowedTypes() : void
- Validate an input for allowed variable types
- validateAllowedValues() : void
- Validate an input for allowed values.
- validateDetails() : void
- Validate a resource section
- validateTypeValue() : void
- Compare an element type and possible literal value or type in the input resource with the definition in the Processor it refers to. If the element type is processor, recursively iterate through, using the calling function _validateProcessor().
Properties
$id
Processor ID.
public
mixed
$id
= ''
Processor ID.
$db
DB connections.
protected
ADOConnection|null
$db
$details
{@inheritDoc}
protected
array<string|int, mixed>
$details
= [
'name' => 'Resource',
'machineName' => 'resource_base',
// phpcs:ignore
'description' => 'Create, edit or fetch a custom API resource for the application. NOTE: in the case of DELETE, the args for the input should be as GET vars - POST vars are not guaranteed on all servers with this method.',
'menu' => 'Admin',
'input' => ['method' => ['description' => 'The HTTP method of the resource (only used if fetching or deleting a resource).', 'cardinality' => [0, 1], 'literalAllowed' => true, 'limitProcessors' => [], 'limitTypes' => ['text'], 'limitValues' => ['get', 'post', 'delete', 'push'], 'default' => null], 'accName' => ['description' => 'The application name that the resource is associated with.', 'cardinality' => [1, 1], 'literalAllowed' => true, 'limitProcessors' => [], 'limitTypes' => ['text'], 'limitValues' => [], 'default' => null], 'appName' => ['description' => 'The application name that the resource is associated with.', 'cardinality' => [1, 1], 'literalAllowed' => true, 'limitProcessors' => [], 'limitTypes' => ['text'], 'limitValues' => [], 'default' => null], 'uri' => [
// phpcs:ignore
'description' => 'The URI for the resource, i.e. the part after the App ID in the URL (only used if fetching or deleting a resource).',
'cardinality' => [0, 1],
'literalAllowed' => true,
'limitProcessors' => [],
'limitTypes' => ['text'],
'limitValues' => [],
'default' => null,
], 'resourceString' => [
// phpcs:ignore
'description' => 'The resource as a string (this input is only used if you are creating or updating a resource).',
'cardinality' => [0, 1],
'literalAllowed' => true,
'limitProcessors' => [],
'limitTypes' => ['text'],
'limitValues' => [],
'default' => null,
], 'resourceFile' => [
// phpcs:ignore
'description' => 'The resource as a string (this input is only used if you are creating or updating a resource).',
'cardinality' => [0, 1],
'literalAllowed' => true,
'limitProcessors' => [],
'limitTypes' => ['text'],
'limitValues' => [],
'default' => null,
]],
]
Details of the processor.
$helper
Processor helper class.
protected
ProcessorHelper
$helper
$logger
Logger object.
protected
MonologWrapper
$logger
$meta
Metadata for the processor.
protected
array<string|int, mixed>
$meta
$request
All the request details.
protected
Request
$request
Request.
$accountMapper
Account mapper class.
private
AccountMapper
$accountMapper
$settings
Config class.
private
Config
$settings
Methods
__construct()
public
__construct(array<string|int, mixed> &$meta, Request &$request, ADOConnection|null $db, MonologWrapper|null $logger) : mixed
Parameters
- $meta : array<string|int, mixed>
-
Metadata for the processor.
- $request : Request
-
The full request object.
- $db : ADOConnection|null
-
The DB connection object.
- $logger : MonologWrapper|null
-
The logger.
Return values
mixed —details()
Return details for processor.
public
details() : array<string|int, mixed>
Return values
array<string|int, mixed> —process()
{@inheritDoc}
public
process() : DataContainer
Tags
Return values
DataContainer —Result of the processor.
val()
Process a variable into a final result for the processor.
public
val(string $key[, bool|null $rawData = false ]) : mixed|DataContainer
This method can be used to process a value in its meta to return a final result that it can use. If the object is a processor, then it will process that down to a final return value, or if the obj is a simple value, then it will return that. Anything else will return an error object.
Setting $realValue to true will force the value to be the actual value, rather than a potential dataContainer.
Parameters
- $key : string
-
The key for the input variable in the meta.
- $rawData : bool|null = false
-
Return the raw data or a DataContainer.
Tags
Return values
mixed|DataContainer —create()
Create or update a resource from input data into the caller's app and acc.
protected
create(array<string|int, mixed> $data, string $accName, string $appName) : DataContainer
Parameters
- $data : array<string|int, mixed>
-
Metadata.
- $accName : string
-
Account name.
- $appName : string
-
Application name.
Tags
Return values
DataContainer —delete()
Delete a resource.
protected
delete(int $appId, string $method, string $uri) : DataContainer
Parameters
- $appId : int
-
Application ID.
- $method : string
-
Resource method.
- $uri : string
-
Resource URI.
Tags
Return values
DataContainer —exportData()
Abstract class used to fetch input resource into the correct array format.
protected
abstract exportData(mixed $data) : mixed
This has to be declared in each derived class, so that we can cater for many output formats.
Parameters
- $data : mixed
-
Input data.
Return values
mixed —generateParams()
Generate the params array for the sql search.
protected
generateParams(string|null $keyword, array<string|int, mixed>|null $keywordCols, string|null $orderBy, string|null $direction) : array<string|int, mixed>
Parameters
- $keyword : string|null
-
Search keyword.
- $keywordCols : array<string|int, mixed>|null
-
Columns to search for the keyword.
- $orderBy : string|null
-
Order by column.
- $direction : string|null
-
Order direction.
Return values
array<string|int, mixed> —importData()
Abstract class used to fetch input resource into the correct array format.
protected
abstract importData(mixed $data) : mixed
This has to be declared in each derived class, so that we can cater for many input formats.
Parameters
- $data : mixed
-
Input data.
Return values
mixed —isDataContainer()
Validate if a set of data is wrapped in a DataContainer object.
protected
isDataContainer(mixed $data) : bool
Parameters
- $data : mixed
-
DataContainer or raw data.
Return values
bool —read()
Fetch a resource.
protected
read(int $appId, string $method, string $uri) : DataContainer
Parameters
- $appId : int
-
Application ID.
- $method : string
-
Resource method.
- $uri : string
-
Resource URI.
Tags
Return values
DataContainer —validateCoreProtection()
Validate application is not core and core not locked.
protected
validateCoreProtection(Application $application) : mixed
Parameters
- $application : Application
Tags
Return values
mixed —validateData()
Validate input data is well formed.
protected
validateData(mixed $data) : void
Parameters
- $data : mixed
-
Data to validate.
Tags
Return values
void —identicalIds()
Search for identical IDs.
private
identicalIds(array<string|int, mixed> $meta) : void
Parameters
- $meta : array<string|int, mixed>
-
Metadata.
Tags
Return values
void —validateAllowedTypes()
Validate an input for allowed variable types
private
validateAllowedTypes(string $type, array<string|int, mixed> $limitTypes, int $min, string $key) : void
Parameters
- $type : string
-
Input value type.
- $limitTypes : array<string|int, mixed>
-
List of limit on variable types.
- $min : int
-
Minimum number of values.
- $key : string
-
The key of the input being validated.
Tags
Return values
void —validateAllowedValues()
Validate an input for allowed values.
private
validateAllowedValues(mixed $val, array<string|int, mixed> $limitValues, int $min, string $key) : void
Parameters
- $val : mixed
-
Input value.
- $limitValues : array<string|int, mixed>
-
List of allowed values.
- $min : int
-
Minimum number of values.
- $key : string
-
The key of the input being validated.
Tags
Return values
void —validateDetails()
Validate a resource section
private
validateDetails(array<string|int, mixed> $meta) : void
Parameters
- $meta : array<string|int, mixed>
-
Metadata.
Tags
Return values
void —validateTypeValue()
Compare an element type and possible literal value or type in the input resource with the definition in the Processor it refers to. If the element type is processor, recursively iterate through, using the calling function _validateProcessor().
private
validateTypeValue(mixed $element, array<string|int, mixed> $accepts, int $id) : void
Parameters
- $element : mixed
-
Value to validate.
- $accepts : array<string|int, mixed>
-
Array of accepted data types.
- $id : int
-
Processor ID.