src/Bridge/Rotation/DebugListingRotationApi.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Bridge\Rotation;
  3. use App\Service\ListingRotationApi;
  4. use Porpaginas\Arrays\ArrayPage;
  5. use Porpaginas\Page;
  6. class DebugListingRotationApi extends ListingRotationApi
  7. {
  8.     private ListingRotationApi $api;
  9.     private array $sample;
  10.     private bool $enabled;
  11.     public function __construct(ListingRotationApi $apistring $samplePathbool $enabled)
  12.     {
  13.         $sample = [];
  14.         if (file_exists($samplePath) && is_readable($samplePath)) {
  15.             $sample json_decode(file_get_contents($samplePath), true);
  16.         }
  17.         $this->api $api;
  18.         $this->sample $sample;
  19.         $this->enabled $enabled;
  20.     }
  21.     public function paginate(array $queryint $pageNumber 1): Page
  22.     {
  23.         if ($this->enabled) {
  24.             return new ArrayPage(
  25.                 $this->sample['items'] ?? [],
  26.                 $this->sample['offset'] ?? 0,
  27.                 $this->sample['limit'] ?? 0,
  28.                 $this->sample['totalCount'] ?? 0,
  29.             );
  30.         }
  31.         return $this->api->paginate($query$pageNumber);
  32.     }
  33. }