ResponseTemplateManager
in package
HEXONET ResponseTemplateManager
Table of Contents
Properties
- $templates : array<string|int, string>
- template container
Methods
- addTemplate() : self
- Add response template to template container
- generateTemplate() : string
- Generate API response template string for given code and description
- getTemplate() : Response
- Get response template instance from template container
- getTemplates() : array<string|int, mixed>
- Return all available response templates
- hasTemplate() : bool
- Check if given template exists in template container
- isTemplateMatchHash() : bool
- Check if given API response hash matches a given template by code and description
- isTemplateMatchPlain() : bool
- Check if given API plain response matches a given template by code and description
Properties
$templates
template container
public
static array<string|int, string>
$templates
= ["404" => "[RESPONSE]\r\nCODE=421\r\nDESCRIPTION=Page not found\r\nEOF\r\n", "500" => "[RESPONSE]\r\nCODE=500\r\nDESCRIPTION=Internal server error\r\nEOF\r\n", "empty" => "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=Empty API response. Probably unreachable API end point {CONNECTION_URL}\r\nEOF\r\n", "error" => "[RESPONSE]\r\nCODE=421\r\nDESCRIPTION=Command failed due to server error. Client should try again\r\nEOF\r\n", "expired" => "[RESPONSE]\r\nCODE=530\r\nDESCRIPTION=SESSION NOT FOUND\r\nEOF\r\n", "httperror" => "[RESPONSE]\r\nCODE=421\r\nDESCRIPTION=Command failed due to HTTP communication error{HTTPERROR}.\r\nEOF\r\n", "invalid" => "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=Invalid API response. Contact Support\r\nEOF\r\n", "nocurl" => "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=API access error: curl_init failed\r\nEOF\r\n", "notfound" => "[RESPONSE]\r\nCODE=500\r\nDESCRIPTION=Response Template not found\r\nEOF\r\n", "unauthorized" => "[RESPONSE]\r\nCODE=530\r\nDESCRIPTION=Unauthorized\r\nEOF\r\n"]
Methods
addTemplate()
Add response template to template container
public
static addTemplate(string $id, string $plain[, string|null $descr = null ]) : self
Parameters
- $id : string
-
template id
- $plain : string
-
API plain response or API response code (when providing $descr)
- $descr : string|null = null
-
API response description
Return values
selfgenerateTemplate()
Generate API response template string for given code and description
public
static generateTemplate(string $code, string $description) : string
Parameters
- $code : string
-
API response code
- $description : string
-
API response description
Return values
string —generate response template string
getTemplate()
Get response template instance from template container
public
static getTemplate(string $id) : Response
Parameters
- $id : string
-
template id
Return values
Response —template instance
getTemplates()
Return all available response templates
public
static getTemplates() : array<string|int, mixed>
Return values
array<string|int, mixed> —all available response instances
hasTemplate()
Check if given template exists in template container
public
static hasTemplate(string $id) : bool
Parameters
- $id : string
-
template id
Return values
bool —boolean result
isTemplateMatchHash()
Check if given API response hash matches a given template by code and description
public
static isTemplateMatchHash(array<string|int, string> $tpl, string $id) : bool
Parameters
- $tpl : array<string|int, string>
-
api response hash
- $id : string
-
template id
Return values
bool —boolean result
isTemplateMatchPlain()
Check if given API plain response matches a given template by code and description
public
static isTemplateMatchPlain(string $plain, string $id) : bool
Parameters
- $plain : string
-
API plain response
- $id : string
-
template id
Return values
bool —boolean result