abstract class AbstractResponseTranslator (View source)

Shared base for all registrar ResponseTranslator implementations.

The translate()/findMatch() pipeline is identical across brands: empty->"empty", an explicit $error parameter resolving to the "httperror" template with {HTTPERROR} injection (see {\CNIC\resolveTemplateId()}), invalid-template fallback, the two description-map rewrite loops, findMatch(), and placeholder replacement. Only a few narrow points differ, supplied by the abstract hooks below:

  • the brand's default template registry (newTemplateManager())
  • the two description rewrite maps (descriptionRegexMap()/descriptionRawPatternMap())
  • the response field carrying the human-readable text (fieldName(): "description" for CNR, "message" for IBS)
  • the "missing/empty required field" check that triggers the invalid fallback (hasMissingRequiredFields(): CODE/DESCRIPTION for CNR, status for IBS)

Placeholder stripping is deliberately unified on the per-field, per-token callback (formerly CNR-only): unknown {UPPER} tokens are removed only inside the human-readable field, leaving {UPPER} content in other data fields untouched. The former IBS behaviour stripped such tokens globally across the whole response, which risked corrupting legitimate data fields — replacePlaceholders() below is the single correct behaviour for both brands.

Methods

newTemplateManager()

The brand's default template registry, used when the caller supplies none.

static array
descriptionRegexMap()

plain-string description keys for translation; keys are preg_quote'd before matching

static array
descriptionRawPatternMap()

raw regex pattern keys for translation; keys are used as-is (not preg_quote'd)

static string
fieldName()

Name of the response field carrying the human-readable text ("description" for CNR, "message" for IBS).

static bool
hasMissingRequiredFields(string $raw)

Whether the raw response is missing or has an empty required field (CNR: CODE/DESCRIPTION, IBS: status) and should therefore fall back to the "invalid" template.

static string
translate(string $raw, array $cmd, array $placeholders = [], string|null $error = null, ResponseTemplateManagerInterface|null $templates = null)

translate a raw api response

static string
replacePlaceholders(string $raw, array $placeholders)

Replace known placeholders in the human-readable field while preserving literal brace content and unknown-token content in other fields.

Details

abstract static protected ResponseTemplateManagerInterface newTemplateManager()

The brand's default template registry, used when the caller supplies none.

A factory, not a shared instance: handing every caller the same object would put the process-global container back that RSRMID-2941 removed — one addTemplate() on it would be visible to every later translate().

static protected array descriptionRegexMap()

plain-string description keys for translation; keys are preg_quote'd before matching

Defaults to no rewrites (RSRMID-2970). A brand that rewrites nothing used to have to say so in four members — two empty private constants and two hooks returning them — which is boilerplate asserting an absence, not a decision recorded.

This is not the "never no-op" case. That directive (see {\CNIC\CNR\Client}, RSRMID-2920) is about a capability the platform cannot honour, where a silent discard hides a caller's mistake. An empty rewrite map is the opposite: a complete and truthful answer to "which messages does this brand rewrite?", from a brand whose answer is "none". Nothing is discarded and no caller is misled — the two rewrite loops in {\CNIC\translate()} iterate over nothing, exactly as they did over an empty constant.

Return Value

array

static protected array descriptionRawPatternMap()

raw regex pattern keys for translation; keys are used as-is (not preg_quote'd)

Defaults to no rewrites, for the reasons on {\CNIC\descriptionRegexMap()}.

Return Value

array

abstract static protected string fieldName()

Name of the response field carrying the human-readable text ("description" for CNR, "message" for IBS).

Return Value

string

abstract static protected bool hasMissingRequiredFields(string $raw)

Whether the raw response is missing or has an empty required field (CNR: CODE/DESCRIPTION, IBS: status) and should therefore fall back to the "invalid" template.

Parameters

string $raw

API raw response (already normalised)

Return Value

bool

static string translate(string $raw, array $cmd, array $placeholders = [], string|null $error = null, ResponseTemplateManagerInterface|null $templates = null)

translate a raw api response

Parameters

string $raw

API raw response

array $cmd

requested API command

array $placeholders
string|null $error

transport error, if any (see {\CNIC\AbstractClient::performRequest()}); non-null means $raw is unusable and the "httperror" template is substituted instead

ResponseTemplateManagerInterface|null $templates

registry to resolve template ids against; null uses the brand's built-ins (see {\CNIC\newTemplateManager()})

Return Value

string

static protected string replacePlaceholders(string $raw, array $placeholders)

Replace known placeholders in the human-readable field while preserving literal brace content and unknown-token content in other fields.

Operates line-by-line on the brand's field (see fieldName()): provided placeholders are substituted, unknown {UPPER} tokens are stripped, and any other brace content (e.g. lowercase %{i} in SPF records) is left untouched.

Parameters

string $raw
array $placeholders

Return Value

string