From 926c1c3aefdab74b0841b96ca3e64ab672840071 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 4 Apr 2021 09:50:28 -0700 Subject: [PATCH] [GH-4510] Deprecate ReservedWordsCommand::setKeywordListClass() --- .../Console/Command/ReservedWordsCommand.php | 65 ++++++++++++------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/src/Tools/Console/Command/ReservedWordsCommand.php b/src/Tools/Console/Command/ReservedWordsCommand.php index a06e2d0f6fd..8cff50f956c 100644 --- a/src/Tools/Console/Command/ReservedWordsCommand.php +++ b/src/Tools/Console/Command/ReservedWordsCommand.php @@ -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; @@ -32,19 +33,8 @@ class ReservedWordsCommand extends Command { - /** @var array> */ - 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 */ + private $keywordLists; /** @var ConnectionProvider */ private $connectionProvider; @@ -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; } /** @@ -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 */ @@ -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: %command.full_name% @@ -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 ); } @@ -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(