| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Ray\AuraSqlModule\Pagerfanta; |
||
| 6 | |||
| 7 | use Aura\Sql\ExtendedPdoInterface; |
||
| 8 | use Override; |
||
| 9 | use PDO; |
||
| 10 | |||
| 11 | use function assert; |
||
| 12 | use function class_exists; |
||
| 13 | |||
| 14 | final readonly class FetchEntity implements FetcherInterface |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 15 | { |
||
| 16 | private string $entity; |
||
| 17 | |||
| 18 | /** @param class-string $entity */ |
||
| 19 | public function __construct(private ExtendedPdoInterface $pdo, string $entity) |
||
| 20 | { |
||
| 21 | assert(class_exists($entity)); |
||
| 22 | $this->entity = $entity; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritDoc} |
||
| 27 | */ |
||
| 28 | #[Override] |
||
| 29 | public function __invoke(string $sql, array $params): array |
||
| 30 | { |
||
| 31 | $pdoStatement = $this->pdo->perform($sql, $params); |
||
| 32 | |||
| 33 | return $pdoStatement->fetchAll(PDO::FETCH_FUNC, /** @param list<mixed> $args */fn (...$args) => /** @psalm-suppress MixedMethodCall */ |
||
| 34 | new $this->entity(...$args)); |
||
| 35 | } |
||
| 36 | } |
||
| 37 |