2
2
3
3
namespace Doctrine \DBAL \Cache ;
4
4
5
- use ArrayIterator ;
6
5
use Doctrine \DBAL \Driver \FetchUtils ;
7
6
use Doctrine \DBAL \Driver \ResultStatement ;
8
- use Doctrine \DBAL \FetchMode ;
9
- use Doctrine \DBAL \ForwardCompatibility \Driver \ResultStatement as ForwardCompatibleResultStatement ;
10
- use InvalidArgumentException ;
11
- use IteratorAggregate ;
12
- use function array_merge ;
13
7
use function array_values ;
14
8
use function count ;
15
9
use function reset ;
16
10
17
- class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement
11
+ class ArrayStatement implements ResultStatement
18
12
{
19
13
/** @var mixed[] */
20
14
private $ data ;
@@ -25,9 +19,6 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
25
19
/** @var int */
26
20
private $ num = 0 ;
27
21
28
- /** @var int */
29
- private $ defaultFetchMode = FetchMode::MIXED ;
30
-
31
22
/**
32
23
* @param mixed[] $data
33
24
*/
@@ -59,97 +50,12 @@ public function columnCount()
59
50
return $ this ->columnCount ;
60
51
}
61
52
62
- /**
63
- * {@inheritdoc}
64
- *
65
- * @deprecated Use one of the fetch- or iterate-related methods.
66
- */
67
- public function setFetchMode ($ fetchMode )
68
- {
69
- $ this ->defaultFetchMode = $ fetchMode ;
70
-
71
- return true ;
72
- }
73
-
74
- /**
75
- * {@inheritdoc}
76
- *
77
- * @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
78
- */
79
- public function getIterator ()
80
- {
81
- $ data = $ this ->fetchAll ();
82
-
83
- return new ArrayIterator ($ data );
84
- }
85
-
86
- /**
87
- * {@inheritdoc}
88
- *
89
- * @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
90
- */
91
- public function fetch ($ fetchMode = null )
92
- {
93
- if (! isset ($ this ->data [$ this ->num ])) {
94
- return false ;
95
- }
96
-
97
- $ row = $ this ->data [$ this ->num ++];
98
- $ fetchMode = $ fetchMode ?? $ this ->defaultFetchMode ;
99
-
100
- if ($ fetchMode === FetchMode::ASSOCIATIVE ) {
101
- return $ row ;
102
- }
103
-
104
- if ($ fetchMode === FetchMode::NUMERIC ) {
105
- return array_values ($ row );
106
- }
107
-
108
- if ($ fetchMode === FetchMode::MIXED ) {
109
- return array_merge ($ row , array_values ($ row ));
110
- }
111
-
112
- if ($ fetchMode === FetchMode::COLUMN ) {
113
- return reset ($ row );
114
- }
115
-
116
- throw new InvalidArgumentException ('Invalid fetch-style given for fetching result. ' );
117
- }
118
-
119
- /**
120
- * {@inheritdoc}
121
- *
122
- * @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
123
- */
124
- public function fetchAll ($ fetchMode = null )
125
- {
126
- $ rows = [];
127
- while ($ row = $ this ->fetch ($ fetchMode )) {
128
- $ rows [] = $ row ;
129
- }
130
-
131
- return $ rows ;
132
- }
133
-
134
- /**
135
- * {@inheritdoc}
136
- *
137
- * @deprecated Use fetchOne() instead.
138
- */
139
- public function fetchColumn ()
140
- {
141
- $ row = $ this ->fetch (FetchMode::NUMERIC );
142
-
143
- // TODO: verify that return false is the correct behavior
144
- return $ row [0 ] ?? false ;
145
- }
146
-
147
53
/**
148
54
* {@inheritdoc}
149
55
*/
150
56
public function fetchNumeric ()
151
57
{
152
- $ row = $ this ->doFetch ();
58
+ $ row = $ this ->fetch ();
153
59
154
60
if ($ row === false ) {
155
61
return false ;
@@ -163,15 +69,15 @@ public function fetchNumeric()
163
69
*/
164
70
public function fetchAssociative ()
165
71
{
166
- return $ this ->doFetch ();
72
+ return $ this ->fetch ();
167
73
}
168
74
169
75
/**
170
76
* {@inheritdoc}
171
77
*/
172
78
public function fetchOne ()
173
79
{
174
- $ row = $ this ->doFetch ();
80
+ $ row = $ this ->fetch ();
175
81
176
82
if ($ row === false ) {
177
83
return false ;
@@ -196,10 +102,18 @@ public function fetchAllAssociative() : array
196
102
return FetchUtils::fetchAllAssociative ($ this );
197
103
}
198
104
105
+ /**
106
+ * {@inheritdoc}
107
+ */
108
+ public function fetchColumn () : array
109
+ {
110
+ return FetchUtils::fetchColumn ($ this );
111
+ }
112
+
199
113
/**
200
114
* @return mixed|false
201
115
*/
202
- private function doFetch ()
116
+ private function fetch ()
203
117
{
204
118
if (! isset ($ this ->data [$ this ->num ])) {
205
119
return false ;
0 commit comments