abstract class AbstractResponseTranslator (View source)

Shared base for all registrar ResponseTranslator implementations.

The translate()/findMatch() pipeline is identical across brands: empty->"empty", "httperror|" splitting, static-template lookup with {HTTPERROR} injection, 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 static template container (templates())
  • 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

static array
templates()

The brand's static template container (id => raw template string).

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 = [])

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

The brand's static template container (id => raw template string).

Return Value

array

abstract static protected array descriptionRegexMap()

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

Return Value

array

abstract static protected array descriptionRawPatternMap()

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

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 = [])

translate a raw api response

Parameters

string $raw

API raw response

array $cmd

requested API command

array $placeholders

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