<?php
namespace App\Bridge\Rotation;
use App\Service\ListingRotationApi;
use Porpaginas\Arrays\ArrayPage;
use Porpaginas\Page;
class DebugListingRotationApi extends ListingRotationApi
{
private ListingRotationApi $api;
private array $sample;
private bool $enabled;
public function __construct(ListingRotationApi $api, string $samplePath, bool $enabled)
{
$sample = [];
if (file_exists($samplePath) && is_readable($samplePath)) {
$sample = json_decode(file_get_contents($samplePath), true);
}
$this->api = $api;
$this->sample = $sample;
$this->enabled = $enabled;
}
public function paginate(array $query, int $pageNumber = 1): Page
{
if ($this->enabled) {
return new ArrayPage(
$this->sample['items'] ?? [],
$this->sample['offset'] ?? 0,
$this->sample['limit'] ?? 0,
$this->sample['totalCount'] ?? 0,
);
}
return $this->api->paginate($query, $pageNumber);
}
}