FacturaScripts

APIResourceClass
in package

AbstractYes

APIResource is an abstract class for any API Resource.

Table of Contents

Properties

$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.

Methods

__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()  : void
Return the array with the result, and HTTP_OK status code.
setError()  : void
Return an error message and the corresponding status.
setOk()  : void
Return a order confirmation. For example for a DELETE order.

Properties

$method

Contains the HTTP method (GET, PUT, PATCH, POST, DELETE).

protected string $method

PUT, PATCH and POST used in the same way.

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>

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) : void
Parameters
$data : array<string|int, mixed>

setError()

Return an error message and the corresponding status.

protected setError(string $message[, array<string|int, mixed>|null $data = null ][, int $status = Response::HTTP_BAD_REQUEST ]) : void

Can also return an array with additional information.

Parameters
$message : string
$data : array<string|int, mixed>|null = null
$status : int = Response::HTTP_BAD_REQUEST

setOk()

Return a order confirmation. For example for a DELETE order.

protected setOk(string $message[, array<string|int, mixed>|null $data = null ]) : void

Can return an array with additional information.

Parameters
$message : string

is an informative text of the confirmation message

$data : array<string|int, mixed>|null = null

with additional information.


        
On this page

Search results