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

static string
generateTemplate(string $code, string $description)

Generate API response template string for given code and description

getTemplate(string $templateId)

Get response template instance from template container.

createResponse(string $raw)

Create a brand Response instance from a template id or raw response.

newResponseParser()

Instantiate the brand's response parser.

static array
matchKeys()

The two response-hash keys this brand compares when matching a template (code/description equivalent, e.g. CODE/DESCRIPTION or status/message).

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.

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

Details

abstract static string generateTemplate(string $code, string $description)

Generate API response template string for given code and description

Parameters

string $code
string $description

Return Value

string

abstract static ResponseInterface getTemplate(string $templateId)

Get response template instance from template container.

Subclasses narrow the return type to their concrete Response.

Parameters

string $templateId

Return Value

ResponseInterface

abstract static protected ResponseInterface createResponse(string $raw)

Create a brand Response instance from a template id or raw response.

Parameters

string $raw

Return Value

ResponseInterface

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).

Return Value

array

static AbstractResponseTemplateManager addTemplate(string $templateId, string $plain, string|null $description = null)

Add response template to template container

Parameters

string $templateId
string $plain

API plain response, or API response code when $description is given

string|null $description

Return Value

AbstractResponseTemplateManager

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().

Return Value

void

static array getTemplates()

Return all available response templates

Return Value

array

static bool hasTemplate(string $templateId)

Check if given template exists in template container

Parameters

string $templateId

Return Value

bool

static bool isTemplateMatchHash(array $responseHash, string $templateId)

Check if given API response hash matches a given template by code and description

Parameters

array $responseHash
string $templateId

Return Value

bool

static bool isTemplateMatchPlain(string $plain, string $templateId)

Check if given API plain response matches a given template by code and description

Parameters

string $plain

API plain response

string $templateId

Return Value

bool