vendor/pimcore/pimcore/lib/Model/Paginator/EventSubscriber/PaginateListingSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * This source file is available under two different licenses:
  6. * - GNU General Public License version 3 (GPLv3)
  7. * - Pimcore Commercial License (PCL)
  8. * Full copyright and license information is available in
  9. * LICENSE.md which is distributed with this source code.
  10. *
  11. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12. * @license http://www.pimcore.org/license GPLv3 and PCL
  13. */
  14. namespace Pimcore\Model\Paginator\EventSubscriber;
  15. use Knp\Component\Pager\Event\ItemsEvent;
  16. use Pimcore\Model\Paginator\PaginateListingInterface;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. class PaginateListingSubscriber implements EventSubscriberInterface
  19. {
  20. public function items(ItemsEvent $event)
  21. {
  22. $paginationAdapter = $event->target;
  23. if ($paginationAdapter instanceof PaginateListingInterface) {
  24. $items = $paginationAdapter->getItems($event->getOffset(), $event->getLimit());
  25. $event->count = $paginationAdapter->count();
  26. $event->items = $items;
  27. $event->stopPropagation();
  28. }
  29. if (!$event->isPropagationStopped()) {
  30. throw new \RuntimeException('Paginator only accepts instances of the type ' .
  31. PaginateListingInterface::class . ' or types defined here: https://github.com/KnpLabs/KnpPaginatorBundle#controller');
  32. }
  33. }
  34. /**
  35. * @internal
  36. */
  37. public static function getSubscribedEvents(): array
  38. {
  39. return [
  40. 'knp_pager.items' => ['items', -5/* other data listeners should be analyzed first*/],
  41. ];
  42. }
  43. }