final class ResponseTranslator extends AbstractResponseTranslator (View source)

IBS ResponseTranslator

Methods

newTemplateManager()

A fresh IBS template registry holding the brand's built-ins.

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

IBS carries the human-readable text in the message field.

static bool
hasMissingRequiredFields(string $raw)

IBS falls back to the "invalid" template when status is missing (JSON or plain) or present but empty. message is optional in success cases and is deliberately not checked.

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

static protected ResponseTemplateManagerInterface newTemplateManager()

A fresh IBS template registry holding the brand's built-ins.

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

static protected string fieldName()

IBS carries the human-readable text in the message field.

Return Value

string

static protected bool hasMissingRequiredFields(string $raw)

IBS falls back to the "invalid" template when status is missing (JSON or plain) or present but empty. message is optional in success cases and is deliberately not checked.

The JSON arm is deliberately unanchored (RSRMID-2972). /"status":/i cannot tell a top-level status from one nested under product[0], so a payload whose only status sits inside a product satisfies the check and passes through untouched. Keep it that way. A stricter pattern would make this return true, and {\CNIC\AbstractResponseTranslator::translate()} replaces the payload wholesale with the "invalid" template — destroying product[0].code and product[0].message before {\CNIC\IBS\Response::getCode()} could read them. Those are exactly the fields RTLDEV-16781 exists to surface, so tightening this regex would discard the data the fallback downstream was added to recover.

The provisioning failure shape this protects always carries a top-level status too, so the leniency is not currently load-bearing for any observed response — it is load-bearing for the class of payload, and the cost of being wrong is silent data loss rather than a visible error. See {\CNIC\IBS\Response::isError()} for the shapes the API actually sends.

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