From 6c367ffb761ab074346ef42b8035c166a5aefebd Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 27 Mar 2021 23:01:29 +0100 Subject: [PATCH] [GH-4554] Deprecate all Statement::fetch* in favor of Result::fetch* --- lib/Doctrine/DBAL/Statement.php | 140 ++++++++++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index f6f6ca5e726..79e984e30a0 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -253,7 +253,7 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', - 'Statement::setFetchMode() is deprecated, use explicit Statement::fetch*() APIs instead.' + 'Statement::setFetchMode() is deprecated, use explicit Result::fetch*() APIs instead.' ); if ($arg2 === null) { @@ -279,7 +279,7 @@ public function getIterator() Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', - 'Statement::getIterator() is deprecated, use Statement::iterateNumeric(), iterateAssociative() ' . + 'Statement::getIterator() is deprecated, use Result::iterateNumeric(), iterateAssociative() ' . 'or iterateColumn() instead.' ); @@ -296,7 +296,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', - 'Statement::fetch() is deprecated, use Statement::fetchNumeric(), fetchAssociative() or fetchOne() instead.' + 'Statement::fetch() is deprecated, use Result::fetchNumeric(), fetchAssociative() or fetchOne() instead.' ); return $this->stmt->fetch($fetchMode); @@ -312,7 +312,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', - 'Statement::fetchAll() is deprecated, use Statement::fetchAllNumeric(), fetchAllAssociative() or ' . + 'Statement::fetchAll() is deprecated, use Result::fetchAllNumeric(), fetchAllAssociative() or ' . 'fetchFirstColumn() instead.' ); @@ -337,7 +337,7 @@ public function fetchColumn($columnIndex = 0) Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4019', - 'Statement::fetchColumn() is deprecated, use Statement::fetchOne() instead.' + 'Statement::fetchColumn() is deprecated, use Result::fetchOne() instead.' ); return $this->stmt->fetchColumn($columnIndex); @@ -346,10 +346,20 @@ public function fetchColumn($columnIndex = 0) /** * {@inheritdoc} * + * @deprecated Use Result::fetchNumeric() instead + * * @throws Exception */ public function fetchNumeric() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { return $this->stmt->fetchNumeric(); @@ -364,10 +374,20 @@ public function fetchNumeric() /** * {@inheritdoc} * + * @deprecated Use Result::fetchAssociative() instead + * * @throws Exception */ public function fetchAssociative() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { return $this->stmt->fetchAssociative(); @@ -382,10 +402,20 @@ public function fetchAssociative() /** * {@inheritDoc} * + * @deprecated Use Result::fetchOne() instead + * * @throws Exception */ public function fetchOne() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { return $this->stmt->fetchOne(); @@ -400,10 +430,20 @@ public function fetchOne() /** * {@inheritdoc} * + * @deprecated Use Result::fetchAllNumeric() instead + * * @throws Exception */ public function fetchAllNumeric(): array { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { return $this->stmt->fetchAllNumeric(); @@ -418,10 +458,20 @@ public function fetchAllNumeric(): array /** * {@inheritdoc} * + * @deprecated Use Result::fetchAllAssociative() instead + * * @throws Exception */ public function fetchAllAssociative(): array { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { return $this->stmt->fetchAllAssociative(); @@ -438,12 +488,22 @@ public function fetchAllAssociative(): array * * The result must contain at least two columns. * + * @deprecated Use Result::fetchAllKeyValue() instead + * * @return array * * @throws Exception */ public function fetchAllKeyValue(): array { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + $this->ensureHasKeyValue(); $data = []; @@ -459,12 +519,22 @@ public function fetchAllKeyValue(): array * Returns an associative array with the keys mapped to the first column and the values being * an associative array representing the rest of the columns and their values. * + * @deprecated Use Result::fetchAllAssociativeIndexed() instead + * * @return array> * * @throws Exception */ public function fetchAllAssociativeIndexed(): array { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + $data = []; foreach ($this->fetchAll(FetchMode::ASSOCIATIVE) as $row) { @@ -477,10 +547,20 @@ public function fetchAllAssociativeIndexed(): array /** * {@inheritdoc} * + * @deprecated Use Result::fetchFirstColumn() instead + * * @throws Exception */ public function fetchFirstColumn(): array { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { return $this->stmt->fetchFirstColumn(); @@ -495,12 +575,22 @@ public function fetchFirstColumn(): array /** * {@inheritDoc} * + * @deprecated Use Result::iterateNumeric() instead + * * @return Traversable> * * @throws Exception */ public function iterateNumeric(): Traversable { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { while (($row = $this->stmt->fetchNumeric()) !== false) { @@ -519,12 +609,22 @@ public function iterateNumeric(): Traversable /** * {@inheritDoc} * + * @deprecated Use Result::iterateAssociative() instead + * * @return Traversable> * * @throws Exception */ public function iterateAssociative(): Traversable { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { while (($row = $this->stmt->fetchAssociative()) !== false) { @@ -546,12 +646,22 @@ public function iterateAssociative(): Traversable * * The result must contain at least two columns. * + * @deprecated Use Result::iterateKeyValue() instead + * * @return Traversable * * @throws Exception */ public function iterateKeyValue(): Traversable { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + $this->ensureHasKeyValue(); foreach ($this->iterateNumeric() as [$key, $value]) { @@ -563,12 +673,22 @@ public function iterateKeyValue(): Traversable * Returns an iterator over the result set with the keys mapped to the first column and the values being * an associative array representing the rest of the columns and their values. * + * @deprecated Use Result::iterateAssociativeIndexed() instead + * * @return Traversable> * * @throws Exception */ public function iterateAssociativeIndexed(): Traversable { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + while (($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) { yield array_shift($row) => $row; } @@ -577,12 +697,22 @@ public function iterateAssociativeIndexed(): Traversable /** * {@inheritDoc} * + * @deprecated Use Result::iterateColumn() instead + * * @return Traversable * * @throws Exception */ public function iterateColumn(): Traversable { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/4554', + 'Statement::%s() is deprecated, use Result::%s() instead.', + __FUNCTION__, + __FUNCTION__ + ); + try { if ($this->stmt instanceof Result) { while (($value = $this->stmt->fetchOne()) !== false) {