Skip to content

Commit 43c5465

Browse files
committed
Replace the concept of the statement fetch modes with an explicit API
1 parent 179ab95 commit 43c5465

File tree

66 files changed

+520
-2131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+520
-2131
lines changed

src/Cache/ArrayStatement.php

Lines changed: 13 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
namespace Doctrine\DBAL\Cache;
44

5-
use ArrayIterator;
65
use Doctrine\DBAL\Driver\FetchUtils;
76
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;
137
use function array_values;
148
use function count;
159
use function reset;
1610

17-
class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement
11+
class ArrayStatement implements ResultStatement
1812
{
1913
/** @var mixed[] */
2014
private $data;
@@ -25,9 +19,6 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
2519
/** @var int */
2620
private $num = 0;
2721

28-
/** @var int */
29-
private $defaultFetchMode = FetchMode::MIXED;
30-
3122
/**
3223
* @param mixed[] $data
3324
*/
@@ -59,97 +50,12 @@ public function columnCount()
5950
return $this->columnCount;
6051
}
6152

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-
14753
/**
14854
* {@inheritdoc}
14955
*/
15056
public function fetchNumeric()
15157
{
152-
$row = $this->doFetch();
58+
$row = $this->fetch();
15359

15460
if ($row === false) {
15561
return false;
@@ -163,15 +69,15 @@ public function fetchNumeric()
16369
*/
16470
public function fetchAssociative()
16571
{
166-
return $this->doFetch();
72+
return $this->fetch();
16773
}
16874

16975
/**
17076
* {@inheritdoc}
17177
*/
17278
public function fetchOne()
17379
{
174-
$row = $this->doFetch();
80+
$row = $this->fetch();
17581

17682
if ($row === false) {
17783
return false;
@@ -196,10 +102,18 @@ public function fetchAllAssociative() : array
196102
return FetchUtils::fetchAllAssociative($this);
197103
}
198104

105+
/**
106+
* {@inheritdoc}
107+
*/
108+
public function fetchColumn() : array
109+
{
110+
return FetchUtils::fetchColumn($this);
111+
}
112+
199113
/**
200114
* @return mixed|false
201115
*/
202-
private function doFetch()
116+
private function fetch()
203117
{
204118
if (! isset($this->data[$this->num])) {
205119
return false;

0 commit comments

Comments
 (0)