final class ResponseTemplateManager extends AbstractResponseTemplateManager (View source)

CNR ResponseTemplateManager

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 CNR Response instance from a template id or raw response.

newResponseParser()

Instantiate the CNR response parser.

static array
matchKeys()

CNR compares templates on the CODE and DESCRIPTION hash keys.

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

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

static ResponseInterface getTemplate(string $templateId)

Get response template instance from template container

Parameters

string $templateId

Return Value

ResponseInterface

static protected ResponseInterface createResponse(string $raw)

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

Parameters

string $raw

Return Value

ResponseInterface

static protected ResponseParserInterface newResponseParser()

Instantiate the CNR response parser.

static protected array matchKeys()

CNR compares templates on the CODE and DESCRIPTION hash keys.

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