abstract class AbstractResponseTemplateManager implements ResponseTemplateManagerInterface, ResponseTemplateFactoryInterface (View source)

Shared base for all registrar ResponseTemplateManager implementations.

The template container plus its add/get/has/match operations are identical across brands; only the built-in 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.

The container is per instance (RSRMID-2941). It used to be a public static array $templates redeclared per brand, read live by {\CNIC\AbstractResponseTranslator}, so addTemplate() in one test class changed response translation in every later one; the resetTemplates() that tried to contain that was a no-op unless addTemplate() had run first and could not undo a direct write to the public property at all. Both are gone. The built-ins now live in an immutable per-brand hook and are copied into each new instance, so an override is scoped to the object that received it and there is nothing left to reset. See {\CNIC\ResponseTemplateManagerInterface} for the registry contract and {\CNIC\ResponseTemplateFactoryInterface} for the Response-production contract this class also implements.

Methods

__construct()

No description

static array
builtinTemplates()

The brand's built-in templates (template id => raw wire text).

createResponseFromTemplateId(string $templateId)

Create a brand Response instance from a template id, resolving it against this registry.

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)

Register a template on this registry.

array
getTemplates()

Every template in this registry as a Response, keyed by template id.

array
getRawTemplates()

Every template in this registry as its raw wire text.

bool
hasTemplate(string $templateId)

Check if given template exists in this registry.

bool
isTemplateMatchHash(array $responseHash, string $templateId)

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

bool
isTemplateMatchPlain(string $plain, string $templateId)

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

Details

__construct()

No description

abstract static protected array builtinTemplates()

The brand's built-in templates (template id => raw wire text).

Declared as a hook over a constant rather than a property so the built-ins cannot be written to: each instance gets a copy, and no route exists to change what the next instance starts from.

Return Value

array

abstract protected ResponseInterface createResponseFromTemplateId(string $templateId)

Create a brand Response instance from a template id, resolving it against this registry.

Never handed wire text (RSRMID-2968): the previous createResponse(string $raw) carried both meanings — {\CNIC\getTemplate()} passed an id, {\CNIC\getTemplates()} passed wire text — and the two only agreed because {\CNIC\AbstractResponseTranslator::translate()} substitutes a raw payload equal to a known id. Register a template whose wire text equals another template's id and they diverged.

Parameters

string $templateId

Return Value

ResponseInterface

abstract 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

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

Register a template on this registry.

Parameters

string $templateId
string $plain

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

string|null $description

Return Value

ResponseTemplateManagerInterface

array getTemplates()

Every template in this registry as a Response, keyed by template id.

Return Value

array

array getRawTemplates()

Every template in this registry as its raw wire text.

Return Value

array

bool hasTemplate(string $templateId)

Check if given template exists in this registry.

Parameters

string $templateId

Return Value

bool

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

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