Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Cache;
4
 
5
use Doctrine\DBAL\Driver\FetchUtils;
6
use Doctrine\DBAL\Driver\Result;
7
 
8
use function array_values;
9
use function count;
10
use function reset;
11
 
12
/** @internal The class is internal to the caching layer implementation. */
13
final class ArrayResult implements Result
14
{
15
    /** @var list<array<string, mixed>> */
16
    private array $data;
17
 
18
    private int $columnCount = 0;
19
    private int $num         = 0;
20
 
21
    /** @param list<array<string, mixed>> $data */
22
    public function __construct(array $data)
23
    {
24
        $this->data = $data;
25
        if (count($data) === 0) {
26
            return;
27
        }
28
 
29
        $this->columnCount = count($data[0]);
30
    }
31
 
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function fetchNumeric()
36
    {
37
        $row = $this->fetch();
38
 
39
        if ($row === false) {
40
            return false;
41
        }
42
 
43
        return array_values($row);
44
    }
45
 
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function fetchAssociative()
50
    {
51
        return $this->fetch();
52
    }
53
 
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function fetchOne()
58
    {
59
        $row = $this->fetch();
60
 
61
        if ($row === false) {
62
            return false;
63
        }
64
 
65
        return reset($row);
66
    }
67
 
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function fetchAllNumeric(): array
72
    {
73
        return FetchUtils::fetchAllNumeric($this);
74
    }
75
 
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function fetchAllAssociative(): array
80
    {
81
        return FetchUtils::fetchAllAssociative($this);
82
    }
83
 
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function fetchFirstColumn(): array
88
    {
89
        return FetchUtils::fetchFirstColumn($this);
90
    }
91
 
92
    public function rowCount(): int
93
    {
94
        return count($this->data);
95
    }
96
 
97
    public function columnCount(): int
98
    {
99
        return $this->columnCount;
100
    }
101
 
102
    public function free(): void
103
    {
104
        $this->data = [];
105
    }
106
 
107
    /** @return array<string, mixed>|false */
108
    private function fetch()
109
    {
110
        if (! isset($this->data[$this->num])) {
111
            return false;
112
        }
113
 
114
        return $this->data[$this->num++];
115
    }
116
}