Skip to content

Commit e3f9b18

Browse files
committed
remove deprecations for ConnectionHelper
1 parent 3710903 commit e3f9b18

File tree

5 files changed

+11
-142
lines changed

5 files changed

+11
-142
lines changed

bin/doctrine-dbal.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22

3-
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
43
use Doctrine\DBAL\Tools\Console\ConsoleRunner;
5-
use Symfony\Component\Console\Helper\HelperSet;
64

75
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
86
$loader = null;
@@ -42,17 +40,7 @@
4240
exit(1);
4341
}
4442

45-
$commands = [];
46-
$helperSetOrConnectionProvider = require $configFile;
43+
$commands = [];
44+
$connectionProvider = require $configFile;
4745

48-
if (! $helperSetOrConnectionProvider instanceof HelperSet && ! $helperSetOrConnectionProvider instanceof ConnectionProvider) {
49-
foreach ($GLOBALS as $candidate) {
50-
if ($candidate instanceof HelperSet) {
51-
$helperSetOrConnectionProvider = $candidate;
52-
53-
break;
54-
}
55-
}
56-
}
57-
58-
ConsoleRunner::run($helperSetOrConnectionProvider, $commands);
46+
ConsoleRunner::run($connectionProvider, $commands);

src/Tools/Console/Command/ReservedWordsCommand.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords;
1717
use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords;
1818
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
19-
use Exception;
2019
use InvalidArgumentException;
2120
use Symfony\Component\Console\Command\Command;
2221
use Symfony\Component\Console\Input\InputInterface;
@@ -28,9 +27,6 @@
2827
use function count;
2928
use function implode;
3029
use function is_string;
31-
use function trigger_error;
32-
33-
use const E_USER_DEPRECATED;
3430

3531
class ReservedWordsCommand extends Command
3632
{
@@ -49,18 +45,13 @@ class ReservedWordsCommand extends Command
4945
'sqlserver' => SQLServer2012Keywords::class,
5046
];
5147

52-
/** @var ConnectionProvider|null */
48+
/** @var ConnectionProvider */
5349
private $connectionProvider;
5450

55-
public function __construct(?ConnectionProvider $connectionProvider = null)
51+
public function __construct(ConnectionProvider $connectionProvider)
5652
{
5753
parent::__construct();
5854
$this->connectionProvider = $connectionProvider;
59-
if ($connectionProvider !== null) {
60-
return;
61-
}
62-
63-
@trigger_error('Not passing a connection provider as the first constructor argument is deprecated', E_USER_DEPRECATED);
6455
}
6556

6657
/**
@@ -174,14 +165,6 @@ private function getConnection(InputInterface $input): Connection
174165
$connectionName = $input->getOption('connection');
175166
assert(is_string($connectionName) || $connectionName === null);
176167

177-
if ($this->connectionProvider === null) {
178-
if ($connectionName !== null) {
179-
throw new Exception('Specifying a connection is only supported when a ConnectionProvider is used.');
180-
}
181-
182-
return $this->getHelper('db')->getConnection();
183-
}
184-
185168
if ($connectionName !== null) {
186169
return $this->connectionProvider->getConnection($connectionName);
187170
}

src/Tools/Console/Command/RunSqlCommand.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Doctrine\DBAL\Connection;
66
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
77
use Doctrine\DBAL\Tools\Dumper;
8-
use Exception;
98
use LogicException;
109
use RuntimeException;
1110
use Symfony\Component\Console\Command\Command;
@@ -19,28 +18,20 @@
1918
use function is_numeric;
2019
use function is_string;
2120
use function stripos;
22-
use function trigger_error;
23-
24-
use const E_USER_DEPRECATED;
2521

2622
/**
2723
* Task for executing arbitrary SQL that can come from a file or directly from
2824
* the command line.
2925
*/
3026
class RunSqlCommand extends Command
3127
{
32-
/** @var ConnectionProvider|null */
28+
/** @var ConnectionProvider */
3329
private $connectionProvider;
3430

35-
public function __construct(?ConnectionProvider $connectionProvider = null)
31+
public function __construct(ConnectionProvider $connectionProvider)
3632
{
3733
parent::__construct();
3834
$this->connectionProvider = $connectionProvider;
39-
if ($connectionProvider !== null) {
40-
return;
41-
}
42-
43-
@trigger_error('Not passing a connection provider as the first constructor argument is deprecated', E_USER_DEPRECATED);
4435
}
4536

4637
/** @return void */
@@ -104,14 +95,6 @@ private function getConnection(InputInterface $input): Connection
10495
$connectionName = $input->getOption('connection');
10596
assert(is_string($connectionName) || $connectionName === null);
10697

107-
if ($this->connectionProvider === null) {
108-
if ($connectionName !== null) {
109-
throw new Exception('Specifying a connection is only supported when a ConnectionProvider is used.');
110-
}
111-
112-
return $this->getHelper('db')->getConnection();
113-
}
114-
11598
if ($connectionName !== null) {
11699
return $this->connectionProvider->getConnection($connectionName);
117100
}

src/Tools/Console/ConsoleRunner.php

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,41 @@
22

33
namespace Doctrine\DBAL\Tools\Console;
44

5-
use Doctrine\DBAL\Connection;
65
use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand;
76
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
8-
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
97
use PackageVersions\Versions;
108
use Symfony\Component\Console\Application;
119
use Symfony\Component\Console\Command\Command;
12-
use Symfony\Component\Console\Helper\HelperSet;
13-
use TypeError;
14-
15-
use function sprintf;
16-
use function trigger_error;
17-
18-
use const E_USER_DEPRECATED;
1910

2011
/**
2112
* Handles running the Console Tools inside Symfony Console context.
2213
*/
2314
class ConsoleRunner
2415
{
25-
/**
26-
* Create a Symfony Console HelperSet
27-
*
28-
* @deprecated use a ConnectionProvider instead.
29-
*
30-
* @return HelperSet
31-
*/
32-
public static function createHelperSet(Connection $connection)
33-
{
34-
return new HelperSet([
35-
'db' => new ConnectionHelper($connection),
36-
]);
37-
}
38-
3916
/**
4017
* Runs console with the given connection provider or helperset (deprecated).
4118
*
42-
* @param ConnectionProvider|HelperSet $helperSetOrConnectionProvider
43-
* @param Command[] $commands
19+
* @param Command[] $commands
4420
*
4521
* @return void
4622
*/
47-
public static function run($helperSetOrConnectionProvider, $commands = [])
23+
public static function run(ConnectionProvider $connectionProvider, $commands = [])
4824
{
4925
$cli = new Application('Doctrine Command Line Interface', Versions::getVersion('doctrine/dbal'));
5026

5127
$cli->setCatchExceptions(true);
52-
53-
$connectionProvider = null;
54-
if ($helperSetOrConnectionProvider instanceof HelperSet) {
55-
@trigger_error(sprintf('Passing an instance of "%s" as the first argument is deprecated. Pass an instance of "%s" instead.', HelperSet::class, ConnectionProvider::class), E_USER_DEPRECATED);
56-
$connectionProvider = null;
57-
$cli->setHelperSet($helperSetOrConnectionProvider);
58-
} elseif ($helperSetOrConnectionProvider instanceof ConnectionProvider) {
59-
$connectionProvider = $helperSetOrConnectionProvider;
60-
} else {
61-
throw new TypeError(sprintf('First argument must be an instance of "%s" or "%s"', HelperSet::class, ConnectionProvider::class));
62-
}
63-
6428
self::addCommands($cli, $connectionProvider);
65-
6629
$cli->addCommands($commands);
6730
$cli->run();
6831
}
6932

7033
/**
7134
* @return void
7235
*/
73-
public static function addCommands(Application $cli, ?ConnectionProvider $connectionProvider = null)
36+
public static function addCommands(Application $cli, ConnectionProvider $connectionProvider)
7437
{
7538
$cli->addCommands([
76-
new RunSqlCommand(),
77-
new ReservedWordsCommand(),
39+
new RunSqlCommand($connectionProvider),
7840
new ReservedWordsCommand($connectionProvider),
7941
]);
8042
}

src/Tools/Console/Helper/ConnectionHelper.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)