diff --git a/packages/rekapager-api-platform/src/Implementation/PagerFactory.php b/packages/rekapager-api-platform/src/Implementation/PagerFactory.php index 540dba8..18ee889 100644 --- a/packages/rekapager-api-platform/src/Implementation/PagerFactory.php +++ b/packages/rekapager-api-platform/src/Implementation/PagerFactory.php @@ -16,6 +16,7 @@ use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; use ApiPlatform\Metadata\UrlGeneratorInterface; +use ApiPlatform\State\Pagination\Pagination; use Rekalogika\Contracts\Rekapager\Exception\InvalidArgumentException; use Rekalogika\Contracts\Rekapager\Exception\UnexpectedValueException; use Rekalogika\Contracts\Rekapager\PageableInterface; @@ -31,6 +32,7 @@ class PagerFactory public function __construct( private readonly ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly PageIdentifierEncoderLocatorInterface $pageIdentifierEncoderLocator, + private readonly Pagination $pagination, private readonly string $pageParameterName = 'page', private readonly int $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH, ) { @@ -49,6 +51,12 @@ public function getPage( ?Operation $operation = null, array $context = [] ): PageInterface { + $itemsPerPage = $this->pagination->getLimit($operation, $context); + + if ($itemsPerPage > 1) { + $pageable = $pageable->withItemsPerPage($itemsPerPage); + } + $pageIdentifierEncoder = $this->pageIdentifierEncoderLocator ->getPageIdentifierEncoder($pageable::getPageIdentifierClass()); diff --git a/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php b/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php index 88864a7..1dfc407 100644 --- a/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php +++ b/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php @@ -82,13 +82,6 @@ public function getResult( array $context = [] ): iterable { $pageable = new KeysetPageable(new QueryBuilderAdapter($queryBuilder)); - - $itemsPerPage = $this->pagination->getLimit($operation, $context); - - if ($itemsPerPage > 1) { - $pageable = $pageable->withItemsPerPage($itemsPerPage); - } - $pager = $this->pagerFactory->createPager($pageable, $operation, $context); return $pager;