Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-4510] Deprecate ReservedWordsCommand::setKeywordListClass() #4587

Merged
merged 1 commit into from Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE.md
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
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