Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AbstractService method: getResponsePaginationLinks #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add AbstractService method: getResponsePaginationLinks
  • Loading branch information
kaxiluo committed Mar 30, 2021
commit 2f66acb80857ac89e56557903c0309fc87cfb46a
17 changes: 17 additions & 0 deletions src/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,21 @@ function ($object) use ($className) {
}, $data
);
}

/** [fetch links(next|previous) from Shopify Link headers]
* supported only in api version 2019-07 of the API and above
* @return array
*/
public function getResponsePaginationLinks(): array
{
$links = ['next' => '', 'previous' => ''];
if ($linkHeader = $this->getLastResponse()->getHeaderLine('Link')) {
foreach (explode(',', $linkHeader) as $item) {
if (preg_match('/<([\s\S]+?)>; rel=\"(next|previous)\"/', $item, $match)) {
$links[$match[2]] = $match[1];
}
}
}
return $links;
}
}