Pionia Core

BaseApiServiceSwitch
in package

AbstractYes

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
author

Jet - ezrajet9@gmail.com

see
BaseResponse

for the response returned by this swicher's processServices method

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

registerServices()

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
version
1.1.7

array can be in the format of ['SERVICE_NAME' => SERVICE_CLASS::class].

example
public function registerServices() :array
{
   return [
      'service1' => new Service1(),
      'service2' => new Service2(),
    ];
}
// version 1.1.7 and above, you can also do the following
public function registerServices() :array
{
  return [
    'service1' => Service1::class,
   'service2' => Service2::class,
  ];
}
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
throws
UserUnauthenticatedException

if the user is not authenticated and the service requires authentication

throws
ResourceNotFoundException|ReflectionException|UserUnauthorizedException

if the SERVICE key is not found, or the service is invalid, or the service is not found*@see BaseResponse for the response returned by this swicher's processServices method

Return values
BaseResponse

The response object


        
On this page

Search results