Skip to content

Commit 2b8c40d

Browse files
committed
[BC] Replaced extension of \PDOStatement with a composition to avoid having to replicate the \PDOStatement interface in ResultStatement
1 parent fedca0b commit 2b8c40d

File tree

12 files changed

+168
-175
lines changed

12 files changed

+168
-175
lines changed

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function columnCount()
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
60+
public function setFetchMode($fetchMode, ...$args)
6161
{
62-
if ($arg2 !== null || $arg3 !== null) {
62+
if (count($args) > 0) {
6363
throw new \InvalidArgumentException("Caching layer does not support 2nd/3rd argument to setFetchMode()");
6464
}
6565

@@ -81,7 +81,7 @@ public function getIterator()
8181
/**
8282
* {@inheritdoc}
8383
*/
84-
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
84+
public function fetch($fetchMode = null, ...$args)
8585
{
8686
if (! isset($this->data[$this->num])) {
8787
return false;
@@ -112,10 +112,10 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
112112
/**
113113
* {@inheritdoc}
114114
*/
115-
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
115+
public function fetchAll($fetchMode = null, ...$args)
116116
{
117117
$rows = [];
118-
while ($row = $this->fetch($fetchMode)) {
118+
while ($row = $this->fetch($fetchMode, ...$args)) {
119119
$rows[] = $row;
120120
}
121121

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function columnCount()
110110
/**
111111
* {@inheritdoc}
112112
*/
113-
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
113+
public function setFetchMode($fetchMode, ...$args)
114114
{
115115
$this->defaultFetchMode = $fetchMode;
116116

@@ -130,7 +130,7 @@ public function getIterator()
130130
/**
131131
* {@inheritdoc}
132132
*/
133-
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
133+
public function fetch($fetchMode = null, ...$args)
134134
{
135135
if ($this->data === null) {
136136
$this->data = [];
@@ -170,10 +170,10 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
170170
/**
171171
* {@inheritdoc}
172172
*/
173-
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
173+
public function fetchAll($fetchMode = null, ...$args)
174174
{
175175
$rows = [];
176-
while ($row = $this->fetch($fetchMode)) {
176+
while ($row = $this->fetch($fetchMode, ...$args)) {
177177
$rows[] = $row;
178178
}
179179

lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,17 @@ public function execute($params = null)
171171
/**
172172
* {@inheritdoc}
173173
*/
174-
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
174+
public function setFetchMode($fetchMode, ...$args)
175175
{
176-
$this->_defaultFetchMode = $fetchMode;
177-
$this->defaultFetchClass = $arg2 ? $arg2 : $this->defaultFetchClass;
178-
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
176+
$this->_defaultFetchMode = $fetchMode;
177+
178+
if (isset($args[0])) {
179+
$this->defaultFetchClass = $args[0];
180+
}
181+
182+
if (isset($args[1])) {
183+
$this->defaultFetchClassCtorArgs = (array) $args[2];
184+
}
179185

180186
return true;
181187
}
@@ -191,7 +197,7 @@ public function getIterator()
191197
/**
192198
* {@inheritdoc}
193199
*/
194-
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
200+
public function fetch($fetchMode = null, ...$args)
195201
{
196202
// do not try fetching from the statement if it's not expected to contain result
197203
// in order to prevent exceptional situation
@@ -214,10 +220,9 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
214220
$className = $this->defaultFetchClass;
215221
$ctorArgs = $this->defaultFetchClassCtorArgs;
216222

217-
if (func_num_args() >= 2) {
218-
$args = func_get_args();
219-
$className = $args[1];
220-
$ctorArgs = $args[2] ?? [];
223+
if (count($args) > 0) {
224+
$className = $args[0];
225+
$ctorArgs = $args[1] ?? [];
221226
}
222227

223228
$result = db2_fetch_object($this->_stmt);
@@ -242,23 +247,23 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
242247
/**
243248
* {@inheritdoc}
244249
*/
245-
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
250+
public function fetchAll($fetchMode = null, ...$args)
246251
{
247252
$rows = [];
248253

249254
switch ($fetchMode) {
250255
case FetchMode::CUSTOM_OBJECT:
251-
while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) {
256+
while (($row = $this->fetch($fetchMode, ...$args)) !== false) {
252257
$rows[] = $row;
253258
}
254259
break;
255260
case FetchMode::COLUMN:
256-
while ($row = $this->fetchColumn()) {
261+
while (($row = $this->fetchColumn()) !== false) {
257262
$rows[] = $row;
258263
}
259264
break;
260265
default:
261-
while ($row = $this->fetch($fetchMode)) {
266+
while (($row = $this->fetch($fetchMode)) !== false) {
262267
$rows[] = $row;
263268
}
264269
}

lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private function _fetch()
250250
/**
251251
* {@inheritdoc}
252252
*/
253-
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
253+
public function fetch($fetchMode = null, ...$args)
254254
{
255255
// do not try fetching from the statement if it's not expected to contain result
256256
// in order to prevent exceptional situation
@@ -304,7 +304,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
304304
/**
305305
* {@inheritdoc}
306306
*/
307-
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
307+
public function fetchAll($fetchMode = null, ...$args)
308308
{
309309
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
310310

@@ -387,7 +387,7 @@ public function columnCount()
387387
/**
388388
* {@inheritdoc}
389389
*/
390-
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
390+
public function setFetchMode($fetchMode, ...$args)
391391
{
392392
$this->_defaultFetchMode = $fetchMode;
393393

lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public function execute($params = null)
343343
/**
344344
* {@inheritdoc}
345345
*/
346-
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
346+
public function setFetchMode($fetchMode, ...$args)
347347
{
348348
$this->_defaultFetchMode = $fetchMode;
349349

@@ -361,7 +361,7 @@ public function getIterator()
361361
/**
362362
* {@inheritdoc}
363363
*/
364-
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
364+
public function fetch($fetchMode = null, ...$args)
365365
{
366366
// do not try fetching from the statement if it's not expected to contain result
367367
// in order to prevent exceptional situation
@@ -392,7 +392,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
392392
/**
393393
* {@inheritdoc}
394394
*/
395-
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
395+
public function fetchAll($fetchMode = null, ...$args)
396396
{
397397
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
398398

lib/Doctrine/DBAL/Driver/PDOConnection.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function __construct($dsn, $user = null, $password = null, array $options
2525
{
2626
try {
2727
parent::__construct($dsn, $user, $password, $options);
28-
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['Doctrine\DBAL\Driver\PDOStatement', []]);
2928
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
3029
} catch (\PDOException $exception) {
3130
throw new PDOException($exception);
@@ -58,7 +57,9 @@ public function getServerVersion()
5857
public function prepare($prepareString, $driverOptions = [])
5958
{
6059
try {
61-
return parent::prepare($prepareString, $driverOptions);
60+
return $this->createStatement(
61+
parent::prepare($prepareString, $driverOptions)
62+
);
6263
} catch (\PDOException $exception) {
6364
throw new PDOException($exception);
6465
}
@@ -70,22 +71,11 @@ public function prepare($prepareString, $driverOptions = [])
7071
public function query()
7172
{
7273
$args = func_get_args();
73-
$argsCount = count($args);
7474

7575
try {
76-
if ($argsCount == 4) {
77-
return parent::query($args[0], $args[1], $args[2], $args[3]);
78-
}
79-
80-
if ($argsCount == 3) {
81-
return parent::query($args[0], $args[1], $args[2]);
82-
}
83-
84-
if ($argsCount == 2) {
85-
return parent::query($args[0], $args[1]);
86-
}
87-
88-
return parent::query($args[0]);
76+
return $this->createStatement(
77+
parent::query(...$args)
78+
);
8979
} catch (\PDOException $exception) {
9080
throw new PDOException($exception);
9181
}
@@ -114,4 +104,15 @@ public function requiresQueryForServerVersion()
114104
{
115105
return false;
116106
}
107+
108+
/**
109+
* Creates a wrapped statement
110+
*
111+
* @param \PDOStatement $stmt
112+
* @return PDOStatement
113+
*/
114+
private function createStatement(\PDOStatement $stmt) : PDOStatement
115+
{
116+
return new PDOStatement($stmt);
117+
}
117118
}

0 commit comments

Comments
 (0)