SocketConfig
class SocketConfig extends AbstractSocketConfig (View source)
IBS SocketConfig
Constants
| MANAGED_OPTIONS |
cURL options the SDK models as first-class configuration, each with the
setter that owns it. Passing one to {setExtraCurlOptions()} raises
{UnsupportedFeatureException} naming the replacement. They are refused not for the transport's sake — {\CNIC\HttpTransport} accepts
all four, and a caller driving it directly still may — but because each
already has a home, and letting the bag carry a second value would put two
answers behind one question: Rejection is eager here, unlike {\CNIC\HttpTransport::PROTECTED_OPTIONS} which is checked on the next request: the config knows immediately, and the error belongs where the mistake is. Options the SDK does not model (CURLOPT_CONNECTTIMEOUT, CURLOPT_IPRESOLVE, ...) stay caller-owned and pass through untouched — the bag is for what the SDK has no opinion about. Keep the list exactly the options that have their own setter: widening it takes away legitimate tuning, narrowing it re-opens a second home. Pinned by AbstractClientCurlOptionsTest::testManagedOptionsAreExactlyTheOnesWithTheirOwnSetter(). |
Properties
| protected string | $login | account name |
from AbstractSocketConfig |
| protected string | $password | account password |
from AbstractSocketConfig |
| protected string | $oteUrl | ||
| protected string | $liveUrl | ||
| protected string | $url | The endpoint requests are sent to — one of {$oteUrl}/{@see $liveUrl} when a system was selected, or whatever {setURL()} was handed. |
from AbstractSocketConfig |
| protected bool | $highPerformance | Whether requests are routed through the co-located high-performance proxy on loopback ({useHighPerformanceConnectionSetup()}). |
from AbstractSocketConfig |
| protected string|null | $proxy | Proxy for API communication, or null for a direct connection. |
from AbstractSocketConfig |
| protected string|null | $referer | Referer sent with API requests, or null to send none. Real state for the same reason as {$proxy}. |
from AbstractSocketConfig |
| protected array<int, mixed> | $curlOptions | Caller-supplied cURL options, over and above what the transport and the dedicated setters above provide. Seeded from {getDefaultCurlOpts()} by the constructor, mutated by {setExtraCurlOptions()} and restored to those defaults by {resetCurlOptions()}. |
from AbstractSocketConfig |
| protected int | $socketTimeout | ||
| protected string[] | $sensitiveFields | IBS carries sensitive data under lower-/camel-case command keys. Mirrors {\CNIC\IBS\Response::$sensitiveFields}. |
Methods
Seed the runtime state that depends on the brand's property defaults.
Set account password to use
Get the endpoint API requests are sent to — the effective URL.
Set another connection url to be used for API communication.
Get the API system currently in use, or null when the configured URL is neither of the brand's two known endpoints.
Select the OT&E system for API communication
Select the LIVE system for API communication (the default)
Route API requests through the co-located high-performance proxy on loopback.
Whether high-performance (loopback proxy) routing is switched on
Set the proxy to use for API communication
Get the proxy configured for API communication, or null for a direct connection
Set the Referer to send with API requests
Get the Referer sent with API requests, or null when none is sent
Brand-default cURL options, used to seed and to reset {$curlOptions}.
Merge additional cURL options into the bag, overriding existing values on key collision (including brand defaults). Use {resetCurlOptions()} to restore the brand defaults afterwards.
Restore the cURL option bag to the brand defaults ({getDefaultCurlOpts()}), discarding anything previously handed to {setExtraCurlOptions()}.
The cURL options to hand the transport for a request: the dedicated proxy/referer state plus the caller's bag.
Set the socket timeout in seconds — the ceiling on a whole API request.
Mask the values of the brand's sensitive command keys (see
$sensitiveFields) so command-level secrets — e.g. a domain transfer
authorization code — never reach the debug log in cleartext. Matching is
case-insensitive to stay robust against casing differences between what a
brand documents and what it actually sends. null values are left
untouched (they are dropped from the request, not logged).
Get POST data container of connection data
Create POST data string out of connection data.
Details
__construct()
Seed the runtime state that depends on the brand's property defaults.
Both seeds have to happen after the subclass's property initialisers, which is why they are here and not inline defaults: {$url} starts at the brand's {$liveUrl} (LIVE is the default system) and {$curlOptions} at the brand's {\CNIC\getDefaultCurlOpts()}.
AbstractSocketConfig
setLogin(string $login)
Set account name to use
string
getLogin()
Get current login
AbstractSocketConfig
setPassword(string $password)
Set account password to use
string
getURL()
Get the endpoint API requests are sent to — the effective URL.
The stored {$url}, with the loopback rewrite applied when high-performance mode is on. That rewrite is resolved here on every read rather than burnt into {$url}, so switching systems afterwards keeps it and {\CNIC\getSystem()} still knows which system was selected.
Note the asymmetry with {\CNIC\setURL()}, which is deliberate: this returns
where requests go, while setURL()/{\CNIC\getSystem()}/{@see \CNIC\isOTE()}
operate on which endpoint was selected. The two differ only under
high-performance routing, and only in that direction — so do not round-trip
one into the other: setURL($cfg->getURL()) burns the loopback rewrite into
the selection and loses the system, which is the very drift this class
exists to prevent.
AbstractSocketConfig
setURL(string $url)
Set another connection url to be used for API communication.
This replaces the endpoint selection wholesale, so a URL that is neither
{$oteUrl} nor {$liveUrl} leaves {\CNIC\getSystem()} answering
null — the SDK cannot know which system an arbitrary host fronts, and
answering with the last selection is how a stored flag comes to disagree
with the URL in use.
string
getOTEUrl()
Get OT&E endpoint URL
string
getLiveUrl()
Get LIVE endpoint URL
System|null
getSystem()
Get the API system currently in use, or null when the configured URL is neither of the brand's two known endpoints.
Derived from {$url}, never stored — a stored copy is a second answer
waiting to contradict the first. The null case is honest rather than
defensive: after setURL("https://staging.example/") the client is on a
system the SDK has no name for, and a caller branching on OT&E-vs-LIVE needs
to see that rather than be told "LIVE".
bool
isOTE()
Check whether the OT&E endpoint is in use
AbstractSocketConfig
useOTESystem()
Select the OT&E system for API communication
AbstractSocketConfig
useLIVESystem()
Select the LIVE system for API communication (the default)
AbstractSocketConfig
useHighPerformanceConnectionSetup()
Route API requests through the co-located high-performance proxy on loopback.
Recorded as a flag and applied by {\CNIC\getURL()} on every read, not by
rewriting {$url} once: an eager rewrite silently costs the caller
isOTE()/getSystem(). It therefore also survives a later
useOTESystem()/useLIVESystem()/setURL() — high-performance routing is
a property of how to reach the endpoint, not of which endpoint. There is
no disable method; construct a fresh client if you need one without it.
bool
usesHighPerformanceConnectionSetup()
Whether high-performance (loopback proxy) routing is switched on
AbstractSocketConfig
setProxy(string $proxy = "")
Set the proxy to use for API communication
string|null
getProxy()
Get the proxy configured for API communication, or null for a direct connection
AbstractSocketConfig
setReferer(string $referer = "")
Set the Referer to send with API requests
string|null
getReferer()
Get the Referer sent with API requests, or null when none is sent
protected array
getDefaultCurlOpts()
Brand-default cURL options, used to seed and to reset {$curlOptions}.
No brand overrides this, and new overrides should be resisted — transport tuning is the caller's decision via {\CNIC\setExtraCurlOptions()}, and a brand default that papers over one environment's networking does not qualify. The bar is a genuinely protocol-mandatory option. The hook is kept because it is the seam {\CNIC\resetCurlOptions()} is defined in terms of: reset restores these defaults rather than blindly wiping the bag. Guarded by ClientConfigSeamTest::testNoBrandOverridesTheDefaultCurlOptsHook().
AbstractSocketConfig
setExtraCurlOptions(array $opts)
Merge additional cURL options into the bag, overriding existing values on key collision (including brand defaults). Use {resetCurlOptions()} to restore the brand defaults afterwards.
What lands here reaches the wire: {\CNIC\HttpTransport::post()} applies the bag over its own defaults, so an option of yours wins on collision. Two sets of keys are refused rather than allowed to become a second answer or a silent loser:
- {\CNIC\MANAGED_OPTIONS} — CURLOPT_TIMEOUT, USERAGENT, PROXY and REFERER each already have a setter that owns them. Rejected here, immediately, naming the setter to use instead.
- {\CNIC\HttpTransport::PROTECTED_OPTIONS} — the request envelope (CURLOPT_URL/POST/POSTFIELDS/RETURNTRANSFER/HEADER) and the TLS verification posture (SSL_VERIFYPEER/SSL_VERIFYHOST). Those belong to the transport, which rejects them on the next request; the config does not pre-empt that check, because the transport is injectable ({\CNIC\TransportInterface}) and which options it owns is its own business.
CURLOPT_HTTPHEADER is additive at the transport: your lines are appended, and restating one of the transport's own throws.
AbstractSocketConfig
resetCurlOptions()
Restore the cURL option bag to the brand defaults ({getDefaultCurlOpts()}), discarding anything previously handed to {setExtraCurlOptions()}.
Scope note: options only. The proxy and the referer are not bag keys
({$proxy}/{@see $referer}), so this does not forget them — reset those
explicitly with setProxy()/setReferer() if that is what you meant.
It restores the defaults rather than clearing the bag, so a brand default would survive; no brand declares one, so today this empties the bag.
array
getCurlOptions()
The cURL options to hand the transport for a request: the dedicated proxy/referer state plus the caller's bag.
The dedicated state goes on the left of the union — the side PHP's +
keeps on a duplicate key — so what {\CNIC\getProxy()} reports is what goes on
the wire, structurally rather than by convention. Do not "simplify" the order
on the grounds that {\CNIC\setExtraCurlOptions()} already refuses those two
keys: that guard is not the only writer of {$curlOptions}, since
{\CNIC\getDefaultCurlOpts()} seeds it through the constructor and
{\CNIC\resetCurlOptions()} re-seeds it, neither passing through the guard. A
brand default of CURLOPT_PROXY would then leave the getter reporting the
setter's value while the request used the default. Pinned by
AbstractClientConfigDriftTest::testDedicatedProxyStateBeatsABrandDefaultOnTheWire().
int
getSocketTimeout()
Get socket timeout in seconds
AbstractSocketConfig
setSocketTimeout(int $timeoutSeconds)
Set the socket timeout in seconds — the ceiling on a whole API request.
The single home for the request timeout: the bag rejects CURLOPT_TIMEOUT ({\CNIC\MANAGED_OPTIONS}), so this is the only way in and {\CNIC\getSocketTimeout()} the only answer. {\CNIC\AbstractClient::setSocketTimeout()} forwards here.
0 carries cURL's meaning — no timeout — and is passed through unchanged.
A negative value is rejected rather than forwarded: cURL refuses it by
returning false from curl_setopt(), whose result curl_setopt_array()
does not surface, so forwarding it would drop the setting with no signal.
protected array
maskSensitiveCommand(array $command)
Mask the values of the brand's sensitive command keys (see
$sensitiveFields) so command-level secrets — e.g. a domain transfer
authorization code — never reach the debug log in cleartext. Matching is
case-insensitive to stay robust against casing differences between what a
brand documents and what it actually sends. null values are left
untouched (they are dropped from the request, not logged).
protected array
getPOSTDataParams(array $command, bool $maskSecrets)
Get POST data container of connection data
string
getPOSTData(array $command = [], bool $maskSecrets = false)
Create POST data string out of connection data.
Purely the encoding step: every parameter, including brand-specific ones,
comes from {\CNIC\getPOSTDataParams()}. Do not reintroduce brand knowledge at
this level — CNR's persistent=1 is appended by its own
getPOSTDataParams(), which is why this method knows nothing brand-specific.