diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Cache/ArrayResult.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Cache/ArrayResult.php')
| -rw-r--r-- | vendor/doctrine/dbal/src/Cache/ArrayResult.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Cache/ArrayResult.php b/vendor/doctrine/dbal/src/Cache/ArrayResult.php new file mode 100644 index 0000000..65b8652 --- /dev/null +++ b/vendor/doctrine/dbal/src/Cache/ArrayResult.php | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Cache; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Driver\FetchUtils; | ||
| 8 | use Doctrine\DBAL\Driver\Result; | ||
| 9 | |||
| 10 | use function array_values; | ||
| 11 | use function count; | ||
| 12 | use function reset; | ||
| 13 | |||
| 14 | /** @internal The class is internal to the caching layer implementation. */ | ||
| 15 | final class ArrayResult implements Result | ||
| 16 | { | ||
| 17 | private readonly int $columnCount; | ||
| 18 | private int $num = 0; | ||
| 19 | |||
| 20 | /** @param list<array<string, mixed>> $data */ | ||
| 21 | public function __construct(private array $data) | ||
| 22 | { | ||
| 23 | $this->columnCount = $data === [] ? 0 : count($data[0]); | ||
| 24 | } | ||
| 25 | |||
| 26 | public function fetchNumeric(): array|false | ||
| 27 | { | ||
| 28 | $row = $this->fetch(); | ||
| 29 | |||
| 30 | if ($row === false) { | ||
| 31 | return false; | ||
| 32 | } | ||
| 33 | |||
| 34 | return array_values($row); | ||
| 35 | } | ||
| 36 | |||
| 37 | public function fetchAssociative(): array|false | ||
| 38 | { | ||
| 39 | return $this->fetch(); | ||
| 40 | } | ||
| 41 | |||
| 42 | public function fetchOne(): mixed | ||
| 43 | { | ||
| 44 | $row = $this->fetch(); | ||
| 45 | |||
| 46 | if ($row === false) { | ||
| 47 | return false; | ||
| 48 | } | ||
| 49 | |||
| 50 | return reset($row); | ||
| 51 | } | ||
| 52 | |||
| 53 | /** | ||
| 54 | * {@inheritDoc} | ||
| 55 | */ | ||
| 56 | public function fetchAllNumeric(): array | ||
| 57 | { | ||
| 58 | return FetchUtils::fetchAllNumeric($this); | ||
| 59 | } | ||
| 60 | |||
| 61 | /** | ||
| 62 | * {@inheritDoc} | ||
| 63 | */ | ||
| 64 | public function fetchAllAssociative(): array | ||
| 65 | { | ||
| 66 | return FetchUtils::fetchAllAssociative($this); | ||
| 67 | } | ||
| 68 | |||
| 69 | /** | ||
| 70 | * {@inheritDoc} | ||
| 71 | */ | ||
| 72 | public function fetchFirstColumn(): array | ||
| 73 | { | ||
| 74 | return FetchUtils::fetchFirstColumn($this); | ||
| 75 | } | ||
| 76 | |||
| 77 | public function rowCount(): int | ||
| 78 | { | ||
| 79 | return count($this->data); | ||
| 80 | } | ||
| 81 | |||
| 82 | public function columnCount(): int | ||
| 83 | { | ||
| 84 | return $this->columnCount; | ||
| 85 | } | ||
| 86 | |||
| 87 | public function free(): void | ||
| 88 | { | ||
| 89 | $this->data = []; | ||
| 90 | } | ||
| 91 | |||
| 92 | /** @return array<string, mixed>|false */ | ||
| 93 | private function fetch(): array|false | ||
| 94 | { | ||
| 95 | if (! isset($this->data[$this->num])) { | ||
| 96 | return false; | ||
| 97 | } | ||
| 98 | |||
| 99 | return $this->data[$this->num++]; | ||
| 100 | } | ||
| 101 | } | ||
