IDNCommandRewriter
final class IDNCommandRewriter (View source)
Rewrites the IDN-bearing parameters of a CNR API command to punycode.
Why this is a module and not a client method
These rules are CNR domain knowledge: which parameter names carry a domain
name, that OBJECTID is a pattern parameter whose content depends on
OBJECTCLASS, and that an already-ASCII value must be left alone. Do not move
them onto the shared {\CNIC\AbstractClient} behind a flag — brand behaviour
on a base shared with IBS and Moniker, gated by a flag whose only job is to
disable it for two brands out of three, is the shape this module replaced, and
it also left the rules reachable only through
ReflectionMethod::setAccessible(). They are called from CNR's
{\CNIC\CNR\Client::buildCommand()} hook — the brand variation point the request
template method already provides — and asserted directly in
tests/CNR/IDNCommandRewriterTest.php.
The conversion itself is not CNR-specific and stays where it was: the vendor
centralnic-reseller/idn-converter, also reachable for callers as the public
{\CNIC\AbstractClient::IDNConvert()}.
Constants
| private ASCII_PATTERN |
Values consisting only of letters, digits, dots and hyphens are already on
the wire alphabet and are passed through untouched. |
| private KEY_PATTERN |
Parameters carrying a domain name that the API does not convert itself.
|
| private OBJECTCLASS_PATTERN |
The Anything else (a contact handle, a user id, ...) must not be converted. |
Methods
Convert the IDN-bearing values of a flattened CNR command to punycode.
Details
static array
rewrite(array $cmd)
Convert the IDN-bearing values of a flattened CNR command to punycode.
Values are rewritten in place, so key order survives — this runs after {\CNIC\CommandFormatter::flattenCommand()} has applied the priority sort, and the wire output must not depend on it.
Without ext-intl the command is returned verbatim: the converter needs
idn_to_ascii(), and an SDK that cannot convert must still be able to send
the ASCII commands that make up the vast majority of traffic.