summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Cache/ArrayResult.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Cache/ArrayResult.php')
-rw-r--r--vendor/doctrine/dbal/src/Cache/ArrayResult.php101
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
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Cache;
6
7use Doctrine\DBAL\Driver\FetchUtils;
8use Doctrine\DBAL\Driver\Result;
9
10use function array_values;
11use function count;
12use function reset;
13
14/** @internal The class is internal to the caching layer implementation. */
15final 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}