BaseApiServiceSwitch
in package
This is the base class for the API service switch. It is used to switch between different services based on the request data.
The child class must implement the registerServices method to return an array of services.
It requires the request to define the SERVICE key in the request data and the ACTION key to define the action to be performed.
The SERVICE is the class that will be called when the SERVICE_NAME is called. The ACTION is the method that will be called on the SERVICE.
Tags
Table of Contents
Methods
- ping() : BaseResponse
- This is just for checking the api status
- processor() : BaseResponse
- This is the sole action to be called in the routes file. It processes the request and returns the response
- registerServices() : array<string|int, mixed>
- This method must be implemented by the child class to return an array of services.
- processServices() : BaseResponse
- This method checks the request data for the `SERVICE` key and processes the service based on it
Methods
ping()
This is just for checking the api status
public
ping(Request $request) : BaseResponse
You can even override it in your own switch class
Parameters
- $request : Request
Return values
BaseResponseprocessor()
This is the sole action to be called in the routes file. It processes the request and returns the response
public
static processor(Request $request) : BaseResponse
Parameters
- $request : Request
Return values
BaseResponseregisterServices()
This method must be implemented by the child class to return an array of services.
protected
abstract registerServices() : array<string|int, mixed>
The array should be in the format of ['SERVICE_NAME' => new SERVICE_CLASS()].
The SERVICE_NAME is the name that will be used in the request data to call the service.
The SERVICE_CLASS is the class that will be called when the SERVICE_NAME is called.
The SERVICE_CLASS must extend the BaseRestService class.
Tags
Return values
array<string|int, mixed> —The array of services
processServices()
This method checks the request data for the `SERVICE` key and processes the service based on it
private
static processServices(Request $request) : BaseResponse
Parameters
- $request : Request
-
The request object
Tags
Return values
BaseResponse —The response object