Files

33 lines
674 B
PHP
Raw Permalink Normal View History

2024-07-20 21:47:21 -04:00
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
2024-06-08 23:58:45 +00:00
namespace BitBadger\PDODocument\Mapper;
2024-07-20 21:47:21 -04:00
use BitBadger\PDODocument\{Configuration, Mode};
use Exception;
2024-06-08 23:58:45 +00:00
/**
* Map an EXISTS result to a boolean value
2024-09-27 02:15:00 +00:00
*
* @implements Mapper<bool>
2024-06-08 23:58:45 +00:00
*/
class ExistsMapper implements Mapper
{
/**
* @inheritDoc
2024-07-20 21:47:21 -04:00
* @throws Exception If the database mode has not been set
2024-06-08 23:58:45 +00:00
*/
public function map(array $result): bool
{
2024-07-20 21:47:21 -04:00
return match (Configuration::mode('map existence result')) {
2024-06-08 23:58:45 +00:00
Mode::PgSQL => (bool)$result[0],
2024-07-21 22:02:16 -04:00
Mode::SQLite => (int)$result[0] > 0,
2024-06-08 23:58:45 +00:00
};
}
}