GovtNZ\SilverStripe\Api\Control\ApiController
For each incoming request, an instance of *ApiController* is created, and this controller then manages the following steps:
*ApiRequestSerialiser* is invoked to parse the request. Request field names
are converted to camelCase at this point.
The controller loads the *swagger.json* file to determine which interface
and function should handle the request.
The controller invokes the implementation class for the required interface
and calls the indicated function.
The implementation class retrieves the requested data.
One of the *ApiResponseSerialiser* classes is invoked to return the data in
the requested format.
Synopsis
class ApiController
extends PageController
{
- // members
- private static array $allowed_actions = ;
- private static array $url_handlers = ;
- private $log = NULL;
- public string $action = '';
- // methods
- public void index()
- public string caseCamel()
- public string caseRequest()
- public string caseSnake()
- public void date3339toDB()
- public string dateDBto3339()
- public array formatOutput()
- public void loadSwagger()
- public void logAdd()
- public null logGet()
- public string param()
- public void setError()
- public void xmlAdd()
- public string xmlLabel()
- private string getImplementerClass()
- private void getResponseSerialiser()
- private void populateErrorResponse()
- private void setStandardHeaders()
- private void testOutput()
Hierarchy
Extends
- PageController
Members
private
- $allowed_actions
- $log
- $url_handlers
public
- $action
Methods
private
- getImplementerClass() — Returns the interface class for the provided request.
- getResponseSerialiser()
- populateErrorResponse()
- setStandardHeaders()
- testOutput()
public
- caseCamel() — Utility function that converts a fieldname to camelCase
- caseRequest() — Utility function that converts a fieldname to whatever case is specified in the request
- caseSnake() — Utility function that converts a fieldname to snake_case
- date3339toDB() — A utility function that converts an RFC3339 timestamp (2015-06-28T00:00:00+12:00) to MySQL format (2015-06-28 00:00:00)
- dateDBto3339() — A utility function that converts a MySQL timestamp (2015-06-28 00:00:00) to RFC3339 format (2015-06-28T00:00:00+12:00)
- formatOutput() — Returns an array with two nodes, one containing the query offset, count and total, the other containing the request data response.
- index()
- loadSwagger() — Loads the swagger.json file matching the requested API version.
- logAdd() — Adds text to the log. For development use only.
- logGet() — Retrieves the log array. For development use only.
- param() — Returns either the request parameter $name, or an empty string if this doesn't exist.
- setError() — Populates the error array and changes the controller status.
- xmlAdd() — Registers an XML label to use for a particular key|parent combination These are only required for a label which does not simply form a plural by adding an "s" Use an asterisk * for any element that's numeric
- xmlLabel() — Returns an XML label for a key|parent combination If no label exists, a simple plural is formed for parent nodes