Class: RequestHandler

abstract

Abstract class for handling the JSON and XML requests.

Implements

Known inheritances

Authors

Oleg Schildt

Package

Source code

 

Properties
protected

Internal variable for storing the API action.

protected

Internal variable for storing the API parameter string.

protected

Internal variable for storing the response headers.

Methods
abstract protected

This is an auxiliary function for adding error messages, warnings, info messages to the response which might have been collected during handling of the request.

protected

Adds a response header to the response.

public

This is the main function that should be called to handle the API request.

abstract protected

This is an auxiliary function for parsing the incoming data.

protected

This function is called after the processing of the request. It should be overridden if you want to perform some standard action after every API request of your library.

protected

This function is called before the processing of the request. It should be overridden if you want to perform some standard action before every API request of your library.

protected

This is an auxiliary function for getting request headers and parsing the API url.

abstract protected

This is an auxiliary function for sending the response.


Property: RequestHandler::$action

protected string $action = "";

Internal variable for storing the API action.

Type

string

Authors

Oleg Schildt

Source code


Property: RequestHandler::$param_string

protected string $param_string = "";

Internal variable for storing the API parameter string.

Type

string

Authors

Oleg Schildt

Source code


Property: RequestHandler::$response_headers

protected array $response_headers = [];

Internal variable for storing the response headers.

Type

array

Authors

Oleg Schildt

Source code


Method: RequestHandler::addMessagesToResponse()

abstract protected function addMessagesToResponse(): void;

This is an auxiliary function for adding error messages, warnings, info messages to the response which might have been collected during handling of the request.

Returns

void

Throws

\SmartFactory\SmartException

It might throw an exception if the content type or data is invalid.

Authors

Oleg Schildt

Source code


Method: RequestHandler::addResponseHeader()

protected function addResponseHeader(string $header, string $value): void;

Adds a response header to the response.

Parameters

Name Pass type Value type Default value Description
$header by value string

The name of the response header.

$value by value string

The value of the response header.

Returns

void

Authors

Oleg Schildt

Source code


Method: RequestHandler::handleRequest()

public function handleRequest(): void;

This is the main function that should be called to handle the API request.

Details

It detects the action, retrieves the request headers, parses the incoming JSON data and tries to call the corresponding method for the API action.

Returns

void

Throws

\Exception

It might throw exceptions in the case of any errors.

Overrides

Authors

Oleg Schildt

Source code


Method: RequestHandler::parseInput()

abstract protected function parseInput(): void;

This is an auxiliary function for parsing the incoming data.

Returns

void

Throws

\SmartFactory\SmartException

It might throw an exception if the content type or data is invalid.

Authors

Oleg Schildt

Source code


Method: RequestHandler::postprocessRequest()

protected function postprocessRequest(): void;

This function is called after the processing of the request. It should be overridden if you want to perform some standard action after every API request of your library.

Returns

void

Authors

Oleg Schildt

Source code


Method: RequestHandler::preprocessRequest()

protected function preprocessRequest(): void;

This function is called before the processing of the request. It should be overridden if you want to perform some standard action before every API request of your library.

Details

The usage example are - validation of the access tokens, checking maintenance mode and reporting it to the user if it is active.

Returns

void

Authors

Oleg Schildt

Source code


Method: RequestHandler::processInputData()

protected function processInputData(): void;

This is an auxiliary function for getting request headers and parsing the API url.

Details

It put the retrieved data into the corresponding properties.

Returns

void

Authors

Oleg Schildt

Source code


Method: RequestHandler::sendResponse()

abstract protected function sendResponse(): void;

This is an auxiliary function for sending the response.

Returns

void

Authors

Oleg Schildt

Source code