ArrayResult.php
2 years ago
CacheException.php
2 years ago
QueryCacheProfile.php
9 months ago
index.php
2 years ago
ArrayResult.php
74 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Cache; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Driver\FetchUtils; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Driver\Result; |
| 6 | use function array_values; |
| 7 | use function count; |
| 8 | use function reset; |
| 9 | final class ArrayResult implements Result |
| 10 | { |
| 11 | private array $data; |
| 12 | private int $columnCount = 0; |
| 13 | private int $num = 0; |
| 14 | public function __construct(array $data) |
| 15 | { |
| 16 | $this->data = $data; |
| 17 | if (count($data) === 0) { |
| 18 | return; |
| 19 | } |
| 20 | $this->columnCount = count($data[0]); |
| 21 | } |
| 22 | public function fetchNumeric() |
| 23 | { |
| 24 | $row = $this->fetch(); |
| 25 | if ($row === \false) { |
| 26 | return \false; |
| 27 | } |
| 28 | return array_values($row); |
| 29 | } |
| 30 | public function fetchAssociative() |
| 31 | { |
| 32 | return $this->fetch(); |
| 33 | } |
| 34 | public function fetchOne() |
| 35 | { |
| 36 | $row = $this->fetch(); |
| 37 | if ($row === \false) { |
| 38 | return \false; |
| 39 | } |
| 40 | return reset($row); |
| 41 | } |
| 42 | public function fetchAllNumeric() : array |
| 43 | { |
| 44 | return FetchUtils::fetchAllNumeric($this); |
| 45 | } |
| 46 | public function fetchAllAssociative() : array |
| 47 | { |
| 48 | return FetchUtils::fetchAllAssociative($this); |
| 49 | } |
| 50 | public function fetchFirstColumn() : array |
| 51 | { |
| 52 | return FetchUtils::fetchFirstColumn($this); |
| 53 | } |
| 54 | public function rowCount() : int |
| 55 | { |
| 56 | return count($this->data); |
| 57 | } |
| 58 | public function columnCount() : int |
| 59 | { |
| 60 | return $this->columnCount; |
| 61 | } |
| 62 | public function free() : void |
| 63 | { |
| 64 | $this->data = []; |
| 65 | } |
| 66 | private function fetch() |
| 67 | { |
| 68 | if (!isset($this->data[$this->num])) { |
| 69 | return \false; |
| 70 | } |
| 71 | return $this->data[$this->num++]; |
| 72 | } |
| 73 | } |
| 74 |