Skip to content

Commit

Permalink
Merge pull request #4587 from morozov/issues/4510
Browse files Browse the repository at this point in the history
[GH-4510] Deprecate ReservedWordsCommand::setKeywordListClass()
  • Loading branch information
morozov authored Apr 5, 2021
2 parents ed497d2 + ee22503 commit 5fb6543
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Use `AbstractSchemaManager::listSchemaNames()` instead.
Instead of implementing `getReservedKeywordsClass()`, `AbstractPlatform` subclasses should implement
`createReservedKeywordsList()`.

## Deprecated `ReservedWordsCommand::setKeywordListClass()`

The usage of `ReservedWordsCommand::setKeywordListClass()` has been deprecated. To add or replace a keyword list,
use `setKeywordList()` instead.

## Deprecated `$driverOptions` argument of `PDO\Statement::bindParam()` and `PDO\SQLSrv\Statement::bindParam()`

The usage of the `$driverOptions` argument of `PDO\Statement::bindParam()` and `PDO\SQLSrv\Statement::bindParam()` is deprecated.
Expand Down
65 changes: 40 additions & 25 deletions src/Tools/Console/Command/ReservedWordsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords;
use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -32,19 +33,8 @@

class ReservedWordsCommand extends Command
{
/** @var array<string,class-string<KeywordList>> */
private $keywordListClasses = [
'db2' => DB2Keywords::class,
'mysql' => MySQLKeywords::class,
'mysql57' => MySQL57Keywords::class,
'mysql80' => MySQL80Keywords::class,
'mariadb102' => MariaDb102Keywords::class,
'oracle' => OracleKeywords::class,
'pgsql' => PostgreSQL94Keywords::class,
'pgsql100' => PostgreSQL100Keywords::class,
'sqlite' => SQLiteKeywords::class,
'sqlserver' => SQLServer2012Keywords::class,
];
/** @var array<string,KeywordList> */
private $keywordLists;

/** @var ConnectionProvider */
private $connectionProvider;
Expand All @@ -53,6 +43,27 @@ public function __construct(ConnectionProvider $connectionProvider)
{
parent::__construct();
$this->connectionProvider = $connectionProvider;

$this->keywordLists = [
'db2' => new DB2Keywords(),
'mariadb102' => new MariaDb102Keywords(),
'mysql' => new MySQLKeywords(),
'mysql57' => new MySQL57Keywords(),
'mysql80' => new MySQL80Keywords(),
'oracle' => new OracleKeywords(),
'pgsql' => new PostgreSQL94Keywords(),
'pgsql100' => new PostgreSQL100Keywords(),
'sqlite' => new SQLiteKeywords(),
'sqlserver' => new SQLServer2012Keywords(),
];
}

/**
* Add or replace a keyword list.
*/
public function setKeywordList(string $name, KeywordList $keywordList): void
{
$this->keywordLists[$name] = $keywordList;
}

/**
Expand All @@ -65,7 +76,14 @@ public function __construct(ConnectionProvider $connectionProvider)
*/
public function setKeywordListClass($name, $class)
{
$this->keywordListClasses[$name] = $class;
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4510',
'ReservedWordsCommand::setKeywordListClass() is deprecated,'
. ' use ReservedWordsCommand::setKeywordList() instead.'
);

$this->keywordLists[$name] = new $class();
}

/** @return void */
Expand All @@ -87,8 +105,7 @@ protected function configure()
Checks if the current database contains tables and columns
with names that are identifiers in this dialect or in other SQL dialects.
By default SQLite, MySQL, PostgreSQL, Microsoft SQL Server and Oracle
keywords are checked:
By default all supported platform keywords are checked:
<info>%command.full_name%</info>
Expand All @@ -99,17 +116,16 @@ protected function configure()
The following keyword lists are currently shipped with Doctrine:
* db2
* mariadb102
* mysql
* mysql57
* mysql80
* mariadb102
* oracle
* pgsql
* pgsql100
* sqlite
* oracle
* sqlserver
* sqlserver2012
* db2 (Not checked by default)
EOT
);
}
Expand All @@ -132,20 +148,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (count($keywordLists) === 0) {
$keywordLists = array_keys($this->keywordListClasses);
$keywordLists = array_keys($this->keywordLists);
}

$keywords = [];
foreach ($keywordLists as $keywordList) {
if (! isset($this->keywordListClasses[$keywordList])) {
if (! isset($this->keywordLists[$keywordList])) {
throw new InvalidArgumentException(
"There exists no keyword list with name '" . $keywordList . "'. " .
'Known lists: ' . implode(', ', array_keys($this->keywordListClasses))
'Known lists: ' . implode(', ', array_keys($this->keywordLists))
);
}

$class = $this->keywordListClasses[$keywordList];
$keywords[] = new $class();
$keywords[] = $this->keywordLists[$keywordList];
}

$output->write(
Expand Down

0 comments on commit 5fb6543

Please sign in to comment.