AbstractResponseTranslator
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
The brand's default template registry, used when the caller supplies none.
plain-string description keys for translation; keys are preg_quote'd before matching
raw regex pattern keys for translation; keys are used as-is (not preg_quote'd)
Name of the response field carrying the human-readable text ("description" for CNR, "message" for IBS).
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.
translate a raw api response
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.
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()}.
abstract static protected string
fieldName()
Name of the response field carrying the human-readable text ("description" for CNR, "message" for IBS).
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.
static string
translate(string $raw, array $cmd, array $placeholders = [], string|null $error = null, ResponseTemplateManagerInterface|null $templates = null)
translate a raw api response
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.