APIResourceClass
in package
APIResource is an abstract class for any API Resource.
Tags
Table of Contents
- $method : string
- Contains the HTTP method (GET, PUT, PATCH, POST, DELETE).
- $params : array<string|int, mixed>
- $request : Request
- Gives us access to the HTTP request parameters.
- $response : Response
- HTTP response object.
- __construct() : mixed
- APIResourceClass constructor.
- doDELETE() : bool
- Process the DELETE request. Overwrite this function to implement is functionality.
- doGET() : bool
- Process the GET request. Overwrite this function to implement is functionality.
- doPOST() : bool
- Process the POST request. Overwrite this function to implement is functionality.
- doPUT() : bool
- Process the PUT request. Overwrite this function to implement is functionality.
- getResources() : array<string|int, mixed>
- Returns an associative array with the resources, where the index is the public name of the resource.
- processResource() : bool
- Process the resource, allowing POST/PUT/DELETE/GET ALL actions
- setResource() : array<string|int, mixed>
- Register a resource
- returnResult() : mixed
- Return the array with the result, and HTTP_OK status code.
- setError() : mixed
- Return an error message and the corresponding status.
- setOk() : mixed
- Return a order confirmation. For example for a DELETE order.
- toolBox() : ToolBox
Properties
$method
Contains the HTTP method (GET, PUT, PATCH, POST, DELETE).
protected
string
$method
PUT, PATCH and POST used in the same way.
$params
protected
array<string|int, mixed>
$params
$request
Gives us access to the HTTP request parameters.
protected
Request
$request
$response
HTTP response object.
protected
Response
$response
Methods
__construct()
APIResourceClass constructor.
public
__construct(Response $response, Request $request, array<string|int, mixed> $params) : mixed
Parameters
- $response : Response
- $request : Request
- $params : array<string|int, mixed>
Return values
mixed —doDELETE()
Process the DELETE request. Overwrite this function to implement is functionality.
public
doDELETE() : bool
It is not defined as abstract because descendants may not need this method if they overwrite processResource.
Return values
bool —doGET()
Process the GET request. Overwrite this function to implement is functionality.
public
doGET() : bool
It is not defined as abstract because descendants may not need this method if they overwrite processResource.
Return values
bool —doPOST()
Process the POST request. Overwrite this function to implement is functionality.
public
doPOST() : bool
It is not defined as abstract because descendants may not need this method if they overwrite processResource.
Return values
bool —doPUT()
Process the PUT request. Overwrite this function to implement is functionality.
public
doPUT() : bool
It is not defined as abstract because descendants may not need this method if they overwrite processResource.
Return values
bool —getResources()
Returns an associative array with the resources, where the index is the public name of the resource.
public
abstract getResources() : array<string|int, mixed>
Return values
array<string|int, mixed> —processResource()
Process the resource, allowing POST/PUT/DELETE/GET ALL actions
public
processResource(string $name) : bool
Parameters
- $name : string
-
of resource, used only if are several.
Return values
bool —setResource()
Register a resource
public
setResource(string $name) : array<string|int, mixed>
Parameters
- $name : string
Return values
array<string|int, mixed> —returnResult()
Return the array with the result, and HTTP_OK status code.
protected
returnResult(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
Return values
mixed —setError()
Return an error message and the corresponding status.
protected
setError(string $message[, array<string|int, mixed> $data = null ][, int $status = Response::HTTP_BAD_REQUEST ]) : mixed
Can also return an array with additional information.
Parameters
- $message : string
- $data : array<string|int, mixed> = null
- $status : int = Response::HTTP_BAD_REQUEST
Return values
mixed —setOk()
Return a order confirmation. For example for a DELETE order.
protected
setOk(string $message[, array<string|int, mixed> $data = null ]) : mixed
Can return an array with additional information.
Parameters
- $message : string
-
is an informative text of the confirmation message
- $data : array<string|int, mixed> = null
-
with additional information.
Return values
mixed —toolBox()
protected
toolBox() : ToolBox