ResponseTemplateManager
HEXONET ResponseTemplateManager
Table of Contents
- $templates : array<string|int, mixed>
- template container
- 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, mixed>
$templates
= ["404" => "[RESPONSE]
CODE=421
DESCRIPTION=Page not found
EOF
", "500" => "[RESPONSE]
CODE=500
DESCRIPTION=Internal server error
EOF
", "empty" => "[RESPONSE]
CODE=423
DESCRIPTION=Empty API response. Probably unreachable API end point {CONNECTION_URL}
EOF
", "error" => "[RESPONSE]
CODE=421
DESCRIPTION=Command failed due to server error. Client should try again
EOF
", "expired" => "[RESPONSE]
CODE=530
DESCRIPTION=SESSION NOT FOUND
EOF
", "httperror" => "[RESPONSE]
CODE=421
DESCRIPTION=Command failed due to HTTP communication error
EOF
", "invalid" => "[RESPONSE]
CODE=423
DESCRIPTION=Invalid API response. Contact Support
EOF
", "nocurl" => "[RESPONSE]
CODE=423
DESCRIPTION=API access error: curl_init failed
EOF
", "notfound" => "[RESPONSE]
CODE=500
DESCRIPTION=Response Template not found
EOF
", "unauthorized" => "[RESPONSE]
CODE=530
DESCRIPTION=Unauthorized
EOF
"]
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
self —generateTemplate()
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, mixed> $tpl, string $id) : bool
Parameters
- $tpl : array<string|int, mixed>
-
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