AbstractResponseTemplateManager
abstract class AbstractResponseTemplateManager (View source)
Shared base for all registrar ResponseTemplateManager implementations.
The template container plus its add/get/has/reset/match operations are identical across brands; only the raw template strings, the generateTemplate() wire format, the two hash keys used for matching, and the concrete Response / ResponseParser classes differ. Concrete subclasses supply those via the abstract hooks below and redeclare their own $templates array.
Properties
| static string[] | $templates | Template container |
Methods
Generate API response template string for given code and description
Get response template instance from template container.
Create a brand Response instance from a template id or raw response.
Instantiate the brand's response parser.
The two response-hash keys this brand compares when matching a template (code/description equivalent, e.g. CODE/DESCRIPTION or status/message).
Add response template to template container
Restore the brand's built-in templates, discarding everything {addTemplate()} has registered since.
Return all available response templates
Check if given template exists in template container
Check if given API response hash matches a given template by code and description
Check if given API plain response matches a given template by code and description
Details
abstract static string
generateTemplate(string $code, string $description)
Generate API response template string for given code and description
abstract static ResponseInterface
getTemplate(string $templateId)
Get response template instance from template container.
Subclasses narrow the return type to their concrete Response.
abstract static protected ResponseInterface
createResponse(string $raw)
Create a brand Response instance from a template id or raw response.
abstract static protected ResponseParserInterface
newResponseParser()
Instantiate the brand's response parser.
The template-manager twin of {\CNIC\AbstractResponse::newResponseParser()}: both name the same brand parser, so the shared pipeline can parse a plain response without each subclass repeating the call.
abstract static protected array
matchKeys()
The two response-hash keys this brand compares when matching a template (code/description equivalent, e.g. CODE/DESCRIPTION or status/message).
static AbstractResponseTemplateManager
addTemplate(string $templateId, string $plain, string|null $description = null)
Add response template to template container
static void
resetTemplates()
Restore the brand's built-in templates, discarding everything {addTemplate()} has registered since.
The container is public static state with process lifetime, so a template registered for one scenario stays visible to every later one — across test classes in the same PHPUnit process, and in any long-lived consumer that registers templates per request. Call this when a scenario ends (e.g. from tearDownAfterClass()) so the next one starts from the brand defaults.
Scope, stated rather than implied: this is the counterpart of {\CNIC\addTemplate()}, not a general undo. It restores what the container held the first time addTemplate() ran for this class, so it is per brand and a no-op when the class was never added to. A direct assignment to the public $templates property is outside its reach — closing that second writer would mean making the property non-public, which {\CNIC\CNR\ResponseTranslator::templates()} reads across a class boundary, so it is a separate change. Go through addTemplate().
static array
getTemplates()
Return all available response templates
static bool
hasTemplate(string $templateId)
Check if given template exists in template container
static bool
isTemplateMatchHash(array $responseHash, string $templateId)
Check if given API response hash matches a given template by code and description
static bool
isTemplateMatchPlain(string $plain, string $templateId)
Check if given API plain response matches a given template by code and description