Documentation

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

Properties

$baseUri

private static string $baseUri = WSC_PIM_API_HOST . '/' . WSC_PIM_API_VERSION

$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
PromiseInterface

fetchSinglePage()

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
throws
GuzzleException

post()

public static post(mixed $endpoint[, null|mixed $lang = null ]) : mixed
Parameters
$endpoint : mixed
$lang : null|mixed = null
Tags
throws
GuzzleException

buildRequest()

private static buildRequest(string $method, string $endpoint[, mixed $lang = null ]) : Request
Parameters
$method : string
$endpoint : string
$lang : mixed = null
Return values
Request

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>

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
Tags
throws
GuzzleException
On this page

Search results