vendor/ezsystems/ezplatform-kernel/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/LocationFilteringHandler.php line 19

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace eZ\Publish\Core\Persistence\Legacy\Filter\Handler;
  8. use eZ\Publish\API\Repository\Values\Filter\Filter;
  9. use eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper as LocationLegacyMapper;
  10. use eZ\Publish\Core\Persistence\Legacy\Filter\Gateway\Content\GatewayDataMapper as ContentGatewayDataMapper;
  11. use eZ\Publish\Core\Persistence\Legacy\Filter\Gateway\Gateway;
  12. use eZ\Publish\SPI\Persistence\Content\LocationWithContentInfo;
  13. use eZ\Publish\SPI\Persistence\Filter\Location\Handler;
  14. use eZ\Publish\SPI\Persistence\Filter\Location\LazyLocationListIterator;
  15. class LocationFilteringHandler implements Handler
  16. {
  17.     /** @var \eZ\Publish\Core\Persistence\Legacy\Filter\Gateway\Gateway */
  18.     private $gateway;
  19.     /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper */
  20.     private $locationMapper;
  21.     /** @var \eZ\Publish\Core\Persistence\Legacy\Filter\Gateway\Content\GatewayDataMapper */
  22.     private $contentGatewayDataMapper;
  23.     public function __construct(
  24.         Gateway $gateway,
  25.         LocationLegacyMapper $locationMapper,
  26.         ContentGatewayDataMapper $contentGatewayDataMapper
  27.     ) {
  28.         $this->gateway $gateway;
  29.         $this->locationMapper $locationMapper;
  30.         $this->contentGatewayDataMapper $contentGatewayDataMapper;
  31.     }
  32.     public function find(Filter $filter): iterable
  33.     {
  34.         $count $this->gateway->count($filter->getCriterion());
  35.         // wrapped list before creating the actual API LocationList to pass totalCount
  36.         // for paginated result a total count is not going to be a number of items in a current page
  37.         $list = new LazyLocationListIterator($count);
  38.         if ($count === 0) {
  39.             return $list;
  40.         }
  41.         $list->prepareIterator(
  42.             $this->gateway->find(
  43.                 $filter->getCriterion(),
  44.                 $filter->getSortClauses(),
  45.                 $filter->getLimit(),
  46.                 $filter->getOffset()
  47.             ),
  48.             // called on each iteration of the  iterator returned by find
  49.             function (array $row): LocationWithContentInfo {
  50.                 return new LocationWithContentInfo(
  51.                     $this->locationMapper->createLocationFromRow($row'location_'),
  52.                     $this->contentGatewayDataMapper->mapContentMetadataToPersistenceContentInfo(
  53.                         $row
  54.                     )
  55.                 );
  56.             }
  57.         );
  58.         return $list;
  59.     }
  60. }