PimService
in package
Table of Contents
Constants
- PAGE_TIMEOUT : mixed = 60.0
Properties
- $baseUri : string
- $client : Client|null
- $sslDisabled : bool
Methods
- fetchAllPages() : array<string|int, mixed>
- Fetches all pages of data from the specified PIM endpoint URL.
- fetchPageAsync() : PromiseInterface
- Starts fetching one page without waiting for it. Resolves to the fetchSinglePage() shape.
- fetchSinglePage() : array<string|int, mixed>
- Fetches a single page of data from the specified PIM endpoint URL.
- get() : mixed
- getClient() : Client
- post() : mixed
- buildRequest() : Request
- formatFailure() : array<string|int, mixed>
- formatPage() : array<string|int, mixed>
- formatResponse() : array<string|int, mixed>
- redactHeaders() : array<string, string>
- Masks the credential headers so a request can be logged without writing the secret down.
- request() : mixed
Constants
PAGE_TIMEOUT
private
mixed
PAGE_TIMEOUT
= 60.0
Properties
$baseUri
private
static string
$baseUri
= WSC_PIM_API_HOST . '/' . WSC_PIM_API_VERSION
$client
private
static Client|null
$client
= null
$sslDisabled
private
static bool
$sslDisabled
= true
Methods
fetchAllPages()
Fetches all pages of data from the specified PIM endpoint URL.
public
static fetchAllPages(string $requestUrl[, bool $logProgress = true ][, null|mixed $lang = null ]) : array<string|int, mixed>
This method performs a paginated request to the given endpoint, appending a page number to the URL for each subsequent request. It continues fetching data until all pages are retrieved. During the process, it logs the progress at every 10 pages and when the fetching is complete, including the total number of pages and items fetched, and the duration of the operation.
Parameters
- $requestUrl : string
-
The base URL of the PIM endpoint with necessary query parameters (excluding the page number).
- $logProgress : bool = true
-
true if precess will write log about process progress.
- $lang : null|mixed = null
Return values
array<string|int, mixed> —An array containing all fetched items combined from all pages.
fetchPageAsync()
Starts fetching one page without waiting for it. Resolves to the fetchSinglePage() shape.
public
static fetchPageAsync(string $requestUrl, int $page[, null|mixed $lang = null ]) : PromiseInterface
Only an HTTP error is turned into a formatted failure; a transport failure (timeout, refused connection) stays a rejection and throws from wait(), the same contract as the synchronous request(), so a populate aborts rather than going live with missing pages.
Parameters
- $requestUrl : string
- $page : int
- $lang : null|mixed = null
Return values
PromiseInterfacefetchSinglePage()
Fetches a single page of data from the specified PIM endpoint URL.
public
static fetchSinglePage(string $requestUrl[, int $page = 1 ][, null|mixed $lang = null ]) : array<string|int, mixed>
This function appends the page number to the base request URL, performs the request, and returns the results along with the next page number if available, or false if there are no more pages.
Parameters
- $requestUrl : string
-
The base URL of the PIM endpoint with necessary query parameters (excluding the page number).
- $page : int = 1
-
The page number to fetch.
- $lang : null|mixed = null
Return values
array<string|int, mixed> —An array with the keys 'results' containing the fetched items and 'next_page' as the next page number or false.
get()
public
static get(mixed $endpoint[, null|mixed $lang = null ]) : mixed
Parameters
- $endpoint : mixed
- $lang : null|mixed = null
Tags
getClient()
public
static getClient() : Client
Return values
Clientpost()
public
static post(mixed $endpoint[, null|mixed $lang = null ]) : mixed
Parameters
- $endpoint : mixed
- $lang : null|mixed = null
Tags
buildRequest()
private
static buildRequest(string $method, string $endpoint[, mixed $lang = null ]) : Request
Parameters
- $method : string
- $endpoint : string
- $lang : mixed = null
Return values
RequestformatFailure()
private
static formatFailure(RequestException $e) : array<string|int, mixed>
Parameters
- $e : RequestException
Return values
array<string|int, mixed>formatPage()
private
static formatPage(array<string|int, mixed> $response, string $url, int $page) : array<string|int, mixed>
Parameters
- $response : array<string|int, mixed>
- $url : string
- $page : int
Return values
array<string|int, mixed>formatResponse()
private
static formatResponse(ResponseInterface $response) : array<string|int, mixed>
Parameters
- $response : ResponseInterface
Return values
array<string|int, mixed>redactHeaders()
Masks the credential headers so a request can be logged without writing the secret down.
private
static redactHeaders(array<string, string> $headers) : array<string, string>
The PIM request headers were logged verbatim on every call, so WSC_PIM_API_TOKEN sat in cleartext in the daily pim-api logs (14-30 days of retention) — and, via the ?debug=true branch, was var_dump()ed straight into the HTTP response for whoever asked. What makes these logs useful is the endpoint and Accept-Language, never the token.
Parameters
- $headers : array<string, string>
Return values
array<string, string>request()
private
static request(mixed $method, mixed $endpoint[, null|mixed $lang = null ][, mixed $timeout = 30.0 ]) : mixed
Parameters
- $method : mixed
- $endpoint : mixed
- $lang : null|mixed = null
- $timeout : mixed = 30.0