AppAPI
extends App
in package
AppAPI is the class used for API.
Tags
Table of Contents
- API_VERSION = 3
- $apiKey : ApiKey
- Contains the ApiKey model
- $dataBase : DataBase
- Database access manager.
- $request : Request
- Gives us access to the HTTP request parameters.
- $response : Response
- HTTP response object.
- $uri : string
- Requested Uri
- __construct() : mixed
- Initializes the app.
- close() : mixed
- Save log and disconnects from the database.
- connect() : bool
- Connects to the database and loads the configuration.
- render() : mixed
- Returns the data into the standard output.
- run() : bool
- Runs the API.
- die() : mixed
- getUriParam() : string
- Returns param number $num in uri.
- ipWarning() : mixed
- Add or increase the attempt counter of the current client IP address.
- isIPBanned() : bool
- Returns true if the client IP has been banned.
- checkAuthToken() : bool
- Check authentication using one of the supported tokens.
- exposeResources() : mixed
- Expose resource.
- getResourcesMap() : array<string|int, mixed>
- Go through all the files in the /Dinamic/Lib/API, collecting the name of all available resources in each of them, and adding them to an array that is returned.
- isAllowed() : bool
- Returns true if the token has the requested access to the resource.
- isDisabled() : bool
- Check if API is disabled. API can't be disabled if FS_API_KEY is defined in the config.php file.
- loadPlugins() : mixed
- Initialize plugins.
- selectResource() : bool
- Selects the resource
- selectVersion() : bool
- Selects the API version if it is supported
Constants
API_VERSION
public
mixed
API_VERSION
= 3
Properties
$apiKey
Contains the ApiKey model
protected
ApiKey
$apiKey
$dataBase
Database access manager.
protected
DataBase
$dataBase
$request
Gives us access to the HTTP request parameters.
protected
Request
$request
$response
HTTP response object.
protected
Response
$response
$uri
Requested Uri
protected
string
$uri
Methods
__construct()
Initializes the app.
public
__construct([string $uri = '/' ]) : mixed
Parameters
- $uri : string = '/'
Return values
mixed —close()
Save log and disconnects from the database.
public
close() : mixed
Return values
mixed —connect()
Connects to the database and loads the configuration.
public
connect() : bool
Return values
bool —render()
Returns the data into the standard output.
public
render() : mixed
Return values
mixed —run()
Runs the API.
public
run() : bool
Return values
bool —die()
protected
die(int $status[, string $message = '' ]) : mixed
Parameters
- $status : int
- $message : string = ''
Return values
mixed —getUriParam()
Returns param number $num in uri.
protected
getUriParam(string $num) : string
Parameters
- $num : string
Return values
string —ipWarning()
Add or increase the attempt counter of the current client IP address.
protected
ipWarning() : mixed
Return values
mixed —isIPBanned()
Returns true if the client IP has been banned.
protected
isIPBanned() : bool
Return values
bool —checkAuthToken()
Check authentication using one of the supported tokens.
private
checkAuthToken() : bool
In the header you have to pass a token using the header 'Token' or the standard 'X-Auth-Token', returning true if the token passed by any of those headers is valid.
We can define a master API KEY in the config.php by defining the constant FS_API_KEY.
Return values
bool —exposeResources()
Expose resource.
private
exposeResources(array<string|int, mixed> &$map) : mixed
Parameters
- $map : array<string|int, mixed>
Return values
mixed —getResourcesMap()
Go through all the files in the /Dinamic/Lib/API, collecting the name of all available resources in each of them, and adding them to an array that is returned.
private
getResourcesMap() : array<string|int, mixed>
Return values
array<string|int, mixed> —isAllowed()
Returns true if the token has the requested access to the resource.
private
isAllowed() : bool
Return values
bool —isDisabled()
Check if API is disabled. API can't be disabled if FS_API_KEY is defined in the config.php file.
private
isDisabled() : bool
Return values
bool —loadPlugins()
Initialize plugins.
private
loadPlugins() : mixed
Return values
mixed —selectResource()
Selects the resource
private
selectResource() : bool
Return values
bool —selectVersion()
Selects the API version if it is supported
private
selectVersion() : bool