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

Make PaginatedResourceCollection usable without Resource object #131

Conversation

mdumoulin
Copy link
Contributor

Reason for this PR

This PR makes PaginatedResourceCollection usable without dedicated Resource object. In such case, You will get a list of HalResource.

$apiHost = 'https://api.shopping-feed.com';
$storeId  = 99999;
$token    = '...';

$options = new Client\ClientOptions();
$options->setBaseUri($apiHost);
$options->setHttpAdapter(new Http\Adapter\GuzzleHTTPAdapter($options));

$client = new Hal\HalClient($options->getBaseUri(), $options->getHttpAdapter());
$client = $client->withToken($token);

$resource = $client->request('GET', "/v1/store/$storeId/order", ['query' => ['limit' => 10]]);

$iterator = new PaginatedResourceIterator(
    new PaginatedResourceCollection($resource)
);

$orders = [];

foreach ($iterator as $order) {
    $orders[] = $order->getProperty('id');
}

@mdumoulin mdumoulin added the enhancement New feature or request label Dec 10, 2024
@mdumoulin mdumoulin self-assigned this Dec 10, 2024
@mdumoulin mdumoulin requested review from maxime-michaut and a team December 10, 2024 17:37
@mdumoulin mdumoulin merged commit 646044d into shoppingflux:master Dec 11, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants