Skip to content

Commit

Permalink
Merge pull request doctrine#4535 from beberlei/Deprecations
Browse files Browse the repository at this point in the history
Deprecations
  • Loading branch information
beberlei authored Mar 27, 2021
2 parents 6d7cd0d + 5a85231 commit ad31968
Show file tree
Hide file tree
Showing 49 changed files with 599 additions and 52 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"php": "^7.1 || ^8",
"ext-pdo": "*",
"doctrine/cache": "^1.0",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.0"
},
"require-dev": {
Expand Down
13 changes: 13 additions & 0 deletions lib/Doctrine/DBAL/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\Deprecations\Deprecation;

use function preg_match;

Expand Down Expand Up @@ -79,6 +80,12 @@ public function setResultCacheImpl(Cache $cacheImpl)
*/
public function setFilterSchemaAssetsExpression($filterExpression)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/3316',
'Configuration::setFilterSchemaAssetsExpression() is deprecated, use setSchemaAssetsFilter() instead.'
);

$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
$this->_attributes['filterSchemaAssetsExpressionCallable']
Expand All @@ -97,6 +104,12 @@ public function setFilterSchemaAssetsExpression($filterExpression)
*/
public function getFilterSchemaAssetsExpression()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/3316',
'Configuration::getFilterSchemaAssetsExpression() is deprecated, use getSchemaAssetsFilter() instead.'
);

return $this->_attributes['filterSchemaAssetsExpression'] ?? null;
}

Expand Down
95 changes: 95 additions & 0 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\DBAL\Result as BaseResult;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use Throwable;
use Traversable;

Expand Down Expand Up @@ -257,6 +258,13 @@ public function getDatabase()
*/
public function getHost()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Connection::getHost() is deprecated, get the database server host from application config ' .
'or as a last resort from internal Connection::getParams() API.'
);

return $this->params['host'] ?? null;
}

Expand All @@ -269,6 +277,13 @@ public function getHost()
*/
public function getPort()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Connection::getPort() is deprecated, get the database server port from application config ' .
'or as a last resort from internal Connection::getParams() API.'
);

return $this->params['port'] ?? null;
}

Expand All @@ -281,6 +296,13 @@ public function getPort()
*/
public function getUsername()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Connection::getUsername() is deprecated, get the username from application config ' .
'or as a last resort from internal Connection::getParams() API.'
);

return $this->params['user'] ?? null;
}

Expand All @@ -293,6 +315,13 @@ public function getUsername()
*/
public function getPassword()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Connection::getPassword() is deprecated, get the password from application config ' .
'or as a last resort from internal Connection::getParams() API.'
);

return $this->params['password'] ?? null;
}

Expand Down Expand Up @@ -542,6 +571,12 @@ public function setAutoCommit($autoCommit)
*/
public function setFetchMode($fetchMode)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Default Fetch Mode configuration is deprecated, use explicit Connection::fetch*() APIs instead.'
);

$this->defaultFetchMode = $fetchMode;
}

Expand All @@ -561,6 +596,12 @@ public function setFetchMode($fetchMode)
*/
public function fetchAssoc($sql, array $params = [], array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Connection::fetchAssoc() is deprecated, use Connection::fetchAssociative() API instead.'
);

return $this->executeQuery($sql, $params, $types)->fetch(FetchMode::ASSOCIATIVE);
}

Expand All @@ -578,6 +619,12 @@ public function fetchAssoc($sql, array $params = [], array $types = [])
*/
public function fetchArray($sql, array $params = [], array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Connection::fetchArray() is deprecated, use Connection::fetchNumeric() API instead.'
);

return $this->executeQuery($sql, $params, $types)->fetch(FetchMode::NUMERIC);
}

Expand All @@ -598,6 +645,12 @@ public function fetchArray($sql, array $params = [], array $types = [])
*/
public function fetchColumn($sql, array $params = [], $column = 0, array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Connection::fetchColumn() is deprecated, use Connection::fetchOne() API instead.'
);

return $this->executeQuery($sql, $params, $types)->fetchColumn($column);
}

Expand Down Expand Up @@ -1339,6 +1392,12 @@ private function ensureForwardCompatibilityStatement(ResultStatement $stmt)
*/
public function project($sql, array $params, Closure $function)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/3823',
'Connection::project() is deprecated without replacement, implement data projections in your own code.'
);

$result = [];
$stmt = $this->executeQuery($sql, $params);

Expand All @@ -1362,6 +1421,12 @@ public function project($sql, array $params, Closure $function)
*/
public function query()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'Connection::query() is deprecated, use Connection::executeQuery() instead.'
);

$connection = $this->getWrappedConnection();

$args = func_get_args();
Expand Down Expand Up @@ -1404,6 +1469,12 @@ public function query()
*/
public function executeUpdate($sql, array $params = [], array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'Connection::executeUpdate() is deprecated, use Connection::executeStatement() instead.'
);

return $this->executeStatement($sql, $params, $types);
}

Expand Down Expand Up @@ -1482,6 +1553,12 @@ public function executeStatement($sql, array $params = [], array $types = [])
*/
public function exec($sql)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'Connection::exec() is deprecated, use Connection::executeStatement() instead.'
);

$connection = $this->getWrappedConnection();

$logger = $this->_config->getSQLLogger();
Expand Down Expand Up @@ -1521,6 +1598,12 @@ public function getTransactionNestingLevel()
*/
public function errorCode()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/3507',
'Connection::errorCode() is deprecated, use getCode() or getSQLState() on Exception instead.'
);

return $this->getWrappedConnection()->errorCode();
}

Expand All @@ -1531,6 +1614,12 @@ public function errorCode()
*/
public function errorInfo()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/3507',
'Connection::errorInfo() is deprecated, use getCode() or getSQLState() on Exception instead.'
);

return $this->getWrappedConnection()->errorInfo();
}

Expand Down Expand Up @@ -2087,6 +2176,12 @@ public function createQueryBuilder()
*/
public function ping()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4119',
'Retry and reconnecting lost connections now happens automatically, ping() will be removed in DBAL 3.'
);

$connection = $this->getWrappedConnection();

if ($connection instanceof PingableConnection) {
Expand Down
19 changes: 7 additions & 12 deletions lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Driver;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;

use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* @deprecated Use PrimaryReadReplicaConnection instead
*
Expand Down Expand Up @@ -94,13 +90,12 @@ public function connect($connectionName = null)

private function deprecated(string $thing, string $instead): void
{
@trigger_error(
sprintf(
'%s is deprecated since doctrine/dbal 2.11 and will be removed in 3.0, use %s instead.',
$thing,
$instead
),
E_USER_DEPRECATED
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4054',
'%s is deprecated since doctrine/dbal 2.11 and will be removed in 3.0, use %s instead.',
$thing,
$instead
);
}
}
8 changes: 8 additions & 0 deletions lib/Doctrine/DBAL/Driver/AbstractException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\DBAL\Driver;

use Doctrine\Deprecations\Deprecation;
use Exception as BaseException;

/**
Expand Down Expand Up @@ -47,6 +48,13 @@ public function __construct($message, $sqlState = null, $errorCode = null)
*/
public function getErrorCode()
{
/** @psalm-suppress ImpureMethodCall */
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4112',
'Driver\AbstractException::getErrorCode() is deprecated, use getSQLState() or getCode() instead.'
);

return $this->errorCode;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use stdClass;

use function assert;
Expand Down Expand Up @@ -82,6 +83,12 @@ public function getServerVersion()
*/
public function requiresQueryForServerVersion()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4114',
'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.'
);

return false;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Driver\IBMDB2;

use Doctrine\DBAL\Driver\AbstractDB2Driver;
use Doctrine\Deprecations\Deprecation;

/**
* IBM DB2 Driver.
Expand Down Expand Up @@ -35,6 +36,12 @@ public function connect(array $params, $username = null, $password = null, array
*/
public function getName()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Driver::getName() is deprecated'
);

return 'ibm_db2';
}
}
7 changes: 7 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\Exception;
use Doctrine\Deprecations\Deprecation;

class Driver extends AbstractMySQLDriver
{
Expand All @@ -24,6 +25,12 @@ public function connect(array $params, $username = null, $password = null, array
*/
public function getName()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3580',
'Driver::getName() is deprecated'
);

return 'mysqli';
}
}
7 changes: 7 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use mysqli;

use function assert;
Expand Down Expand Up @@ -135,6 +136,12 @@ public function getServerVersion()
*/
public function requiresQueryForServerVersion()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4114',
'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.'
);

return false;
}

Expand Down
Loading

0 comments on commit ad31968

Please sign in to comment.