Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
905f0a00
Commit
905f0a00
authored
Jun 09, 2020
by
David Maicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove deprecations for ConnectionHelper
parent
3710903b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
151 deletions
+17
-151
doctrine-dbal.php
bin/doctrine-dbal.php
+3
-15
ReservedWordsCommand.php
src/Tools/Console/Command/ReservedWordsCommand.php
+2
-19
RunSqlCommand.php
src/Tools/Console/Command/RunSqlCommand.php
+2
-19
ConsoleRunner.php
src/Tools/Console/ConsoleRunner.php
+4
-42
ConnectionHelper.php
src/Tools/Console/Helper/ConnectionHelper.php
+0
-47
RunSqlCommandTest.php
tests/Tools/Console/RunSqlCommandTest.php
+6
-9
No files found.
bin/doctrine-dbal.php
View file @
905f0a00
<?php
<?php
use
Doctrine\DBAL\Tools\Console\ConnectionProvider
;
use
Doctrine\DBAL\Tools\Console\ConsoleRunner
;
use
Doctrine\DBAL\Tools\Console\ConsoleRunner
;
use
Symfony\Component\Console\Helper\HelperSet
;
$files
=
[
__DIR__
.
'/../vendor/autoload.php'
,
__DIR__
.
'/../../../autoload.php'
];
$files
=
[
__DIR__
.
'/../vendor/autoload.php'
,
__DIR__
.
'/../../../autoload.php'
];
$loader
=
null
;
$loader
=
null
;
...
@@ -42,17 +40,7 @@ if (! is_readable($configFile)) {
...
@@ -42,17 +40,7 @@ if (! is_readable($configFile)) {
exit
(
1
);
exit
(
1
);
}
}
$commands
=
[];
$commands
=
[];
$
helperSetOrC
onnectionProvider
=
require
$configFile
;
$
c
onnectionProvider
=
require
$configFile
;
if
(
!
$helperSetOrConnectionProvider
instanceof
HelperSet
&&
!
$helperSetOrConnectionProvider
instanceof
ConnectionProvider
)
{
ConsoleRunner
::
run
(
$connectionProvider
,
$commands
);
foreach
(
$GLOBALS
as
$candidate
)
{
if
(
$candidate
instanceof
HelperSet
)
{
$helperSetOrConnectionProvider
=
$candidate
;
break
;
}
}
}
ConsoleRunner
::
run
(
$helperSetOrConnectionProvider
,
$commands
);
src/Tools/Console/Command/ReservedWordsCommand.php
View file @
905f0a00
...
@@ -16,7 +16,6 @@ use Doctrine\DBAL\Platforms\Keywords\SQLAnywhereKeywords;
...
@@ -16,7 +16,6 @@ use Doctrine\DBAL\Platforms\Keywords\SQLAnywhereKeywords;
use
Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords
;
use
Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords
;
use
Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords
;
use
Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords
;
use
Doctrine\DBAL\Tools\Console\ConnectionProvider
;
use
Doctrine\DBAL\Tools\Console\ConnectionProvider
;
use
Exception
;
use
InvalidArgumentException
;
use
InvalidArgumentException
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Input\InputInterface
;
...
@@ -28,9 +27,6 @@ use function assert;
...
@@ -28,9 +27,6 @@ use function assert;
use
function
count
;
use
function
count
;
use
function
implode
;
use
function
implode
;
use
function
is_string
;
use
function
is_string
;
use
function
trigger_error
;
use
const
E_USER_DEPRECATED
;
class
ReservedWordsCommand
extends
Command
class
ReservedWordsCommand
extends
Command
{
{
...
@@ -49,18 +45,13 @@ class ReservedWordsCommand extends Command
...
@@ -49,18 +45,13 @@ class ReservedWordsCommand extends Command
'sqlserver'
=>
SQLServer2012Keywords
::
class
,
'sqlserver'
=>
SQLServer2012Keywords
::
class
,
];
];
/** @var ConnectionProvider
|null
*/
/** @var ConnectionProvider */
private
$connectionProvider
;
private
$connectionProvider
;
public
function
__construct
(
?
ConnectionProvider
$connectionProvider
=
null
)
public
function
__construct
(
ConnectionProvider
$connectionProvider
)
{
{
parent
::
__construct
();
parent
::
__construct
();
$this
->
connectionProvider
=
$connectionProvider
;
$this
->
connectionProvider
=
$connectionProvider
;
if
(
$connectionProvider
!==
null
)
{
return
;
}
@
trigger_error
(
'Not passing a connection provider as the first constructor argument is deprecated'
,
E_USER_DEPRECATED
);
}
}
/**
/**
...
@@ -174,14 +165,6 @@ EOT
...
@@ -174,14 +165,6 @@ EOT
$connectionName
=
$input
->
getOption
(
'connection'
);
$connectionName
=
$input
->
getOption
(
'connection'
);
assert
(
is_string
(
$connectionName
)
||
$connectionName
===
null
);
assert
(
is_string
(
$connectionName
)
||
$connectionName
===
null
);
if
(
$this
->
connectionProvider
===
null
)
{
if
(
$connectionName
!==
null
)
{
throw
new
Exception
(
'Specifying a connection is only supported when a ConnectionProvider is used.'
);
}
return
$this
->
getHelper
(
'db'
)
->
getConnection
();
}
if
(
$connectionName
!==
null
)
{
if
(
$connectionName
!==
null
)
{
return
$this
->
connectionProvider
->
getConnection
(
$connectionName
);
return
$this
->
connectionProvider
->
getConnection
(
$connectionName
);
}
}
...
...
src/Tools/Console/Command/RunSqlCommand.php
View file @
905f0a00
...
@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Tools\Console\Command;
...
@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Tools\Console\Command;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Tools\Console\ConnectionProvider
;
use
Doctrine\DBAL\Tools\Console\ConnectionProvider
;
use
Doctrine\DBAL\Tools\Dumper
;
use
Doctrine\DBAL\Tools\Dumper
;
use
Exception
;
use
LogicException
;
use
LogicException
;
use
RuntimeException
;
use
RuntimeException
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Command\Command
;
...
@@ -19,9 +18,6 @@ use function is_bool;
...
@@ -19,9 +18,6 @@ use function is_bool;
use
function
is_numeric
;
use
function
is_numeric
;
use
function
is_string
;
use
function
is_string
;
use
function
stripos
;
use
function
stripos
;
use
function
trigger_error
;
use
const
E_USER_DEPRECATED
;
/**
/**
* Task for executing arbitrary SQL that can come from a file or directly from
* Task for executing arbitrary SQL that can come from a file or directly from
...
@@ -29,18 +25,13 @@ use const E_USER_DEPRECATED;
...
@@ -29,18 +25,13 @@ use const E_USER_DEPRECATED;
*/
*/
class
RunSqlCommand
extends
Command
class
RunSqlCommand
extends
Command
{
{
/** @var ConnectionProvider
|null
*/
/** @var ConnectionProvider */
private
$connectionProvider
;
private
$connectionProvider
;
public
function
__construct
(
?
ConnectionProvider
$connectionProvider
=
null
)
public
function
__construct
(
ConnectionProvider
$connectionProvider
)
{
{
parent
::
__construct
();
parent
::
__construct
();
$this
->
connectionProvider
=
$connectionProvider
;
$this
->
connectionProvider
=
$connectionProvider
;
if
(
$connectionProvider
!==
null
)
{
return
;
}
@
trigger_error
(
'Not passing a connection provider as the first constructor argument is deprecated'
,
E_USER_DEPRECATED
);
}
}
/** @return void */
/** @return void */
...
@@ -104,14 +95,6 @@ EOT
...
@@ -104,14 +95,6 @@ EOT
$connectionName
=
$input
->
getOption
(
'connection'
);
$connectionName
=
$input
->
getOption
(
'connection'
);
assert
(
is_string
(
$connectionName
)
||
$connectionName
===
null
);
assert
(
is_string
(
$connectionName
)
||
$connectionName
===
null
);
if
(
$this
->
connectionProvider
===
null
)
{
if
(
$connectionName
!==
null
)
{
throw
new
Exception
(
'Specifying a connection is only supported when a ConnectionProvider is used.'
);
}
return
$this
->
getHelper
(
'db'
)
->
getConnection
();
}
if
(
$connectionName
!==
null
)
{
if
(
$connectionName
!==
null
)
{
return
$this
->
connectionProvider
->
getConnection
(
$connectionName
);
return
$this
->
connectionProvider
->
getConnection
(
$connectionName
);
}
}
...
...
src/Tools/Console/ConsoleRunner.php
View file @
905f0a00
...
@@ -2,67 +2,30 @@
...
@@ -2,67 +2,30 @@
namespace
Doctrine\DBAL\Tools\Console
;
namespace
Doctrine\DBAL\Tools\Console
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand
;
use
Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand
;
use
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
;
use
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
;
use
Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper
;
use
PackageVersions\Versions
;
use
PackageVersions\Versions
;
use
Symfony\Component\Console\Application
;
use
Symfony\Component\Console\Application
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Helper\HelperSet
;
use
TypeError
;
use
function
sprintf
;
use
function
trigger_error
;
use
const
E_USER_DEPRECATED
;
/**
/**
* Handles running the Console Tools inside Symfony Console context.
* Handles running the Console Tools inside Symfony Console context.
*/
*/
class
ConsoleRunner
class
ConsoleRunner
{
{
/**
* Create a Symfony Console HelperSet
*
* @deprecated use a ConnectionProvider instead.
*
* @return HelperSet
*/
public
static
function
createHelperSet
(
Connection
$connection
)
{
return
new
HelperSet
([
'db'
=>
new
ConnectionHelper
(
$connection
),
]);
}
/**
/**
* Runs console with the given connection provider or helperset (deprecated).
* Runs console with the given connection provider or helperset (deprecated).
*
*
* @param ConnectionProvider|HelperSet $helperSetOrConnectionProvider
* @param Command[] $commands
* @param Command[] $commands
*
*
* @return void
* @return void
*/
*/
public
static
function
run
(
$helperSetOrC
onnectionProvider
,
$commands
=
[])
public
static
function
run
(
ConnectionProvider
$c
onnectionProvider
,
$commands
=
[])
{
{
$cli
=
new
Application
(
'Doctrine Command Line Interface'
,
Versions
::
getVersion
(
'doctrine/dbal'
));
$cli
=
new
Application
(
'Doctrine Command Line Interface'
,
Versions
::
getVersion
(
'doctrine/dbal'
));
$cli
->
setCatchExceptions
(
true
);
$cli
->
setCatchExceptions
(
true
);
$connectionProvider
=
null
;
if
(
$helperSetOrConnectionProvider
instanceof
HelperSet
)
{
@
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
);
$connectionProvider
=
null
;
$cli
->
setHelperSet
(
$helperSetOrConnectionProvider
);
}
elseif
(
$helperSetOrConnectionProvider
instanceof
ConnectionProvider
)
{
$connectionProvider
=
$helperSetOrConnectionProvider
;
}
else
{
throw
new
TypeError
(
sprintf
(
'First argument must be an instance of "%s" or "%s"'
,
HelperSet
::
class
,
ConnectionProvider
::
class
));
}
self
::
addCommands
(
$cli
,
$connectionProvider
);
self
::
addCommands
(
$cli
,
$connectionProvider
);
$cli
->
addCommands
(
$commands
);
$cli
->
addCommands
(
$commands
);
$cli
->
run
();
$cli
->
run
();
}
}
...
@@ -70,11 +33,10 @@ class ConsoleRunner
...
@@ -70,11 +33,10 @@ class ConsoleRunner
/**
/**
* @return void
* @return void
*/
*/
public
static
function
addCommands
(
Application
$cli
,
?
ConnectionProvider
$connectionProvider
=
null
)
public
static
function
addCommands
(
Application
$cli
,
ConnectionProvider
$connectionProvider
)
{
{
$cli
->
addCommands
([
$cli
->
addCommands
([
new
RunSqlCommand
(),
new
RunSqlCommand
(
$connectionProvider
),
new
ReservedWordsCommand
(),
new
ReservedWordsCommand
(
$connectionProvider
),
new
ReservedWordsCommand
(
$connectionProvider
),
]);
]);
}
}
...
...
src/Tools/Console/Helper/ConnectionHelper.php
deleted
100644 → 0
View file @
3710903b
<?php
namespace
Doctrine\DBAL\Tools\Console\Helper
;
use
Doctrine\DBAL\Connection
;
use
Symfony\Component\Console\Helper\Helper
;
/**
* Doctrine CLI Connection Helper.
*
* @deprecated use a ConnectionProvider instead.
*/
class
ConnectionHelper
extends
Helper
{
/**
* The Doctrine database Connection.
*
* @var Connection
*/
protected
$_connection
;
/**
* @param Connection $connection The Doctrine database Connection.
*/
public
function
__construct
(
Connection
$connection
)
{
$this
->
_connection
=
$connection
;
}
/**
* Retrieves the Doctrine database Connection.
*
* @return Connection
*/
public
function
getConnection
()
{
return
$this
->
_connection
;
}
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
'connection'
;
}
}
tests/Tools/Console/RunSqlCommandTest.php
View file @
905f0a00
...
@@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Tests\Tools\Console;
...
@@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Tests\Tools\Console;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
;
use
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
;
use
Doctrine\DBAL\Tools\Console\Con
soleRunn
er
;
use
Doctrine\DBAL\Tools\Console\Con
nectionProvider\SingleConnectionProvid
er
;
use
LogicException
;
use
LogicException
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
...
@@ -24,20 +24,17 @@ class RunSqlCommandTest extends TestCase
...
@@ -24,20 +24,17 @@ class RunSqlCommandTest extends TestCase
protected
function
setUp
()
:
void
protected
function
setUp
()
:
void
{
{
$application
=
new
Application
();
$application
->
add
(
new
RunSqlCommand
());
$this
->
command
=
$application
->
find
(
'dbal:run-sql'
);
$this
->
commandTester
=
new
CommandTester
(
$this
->
command
);
$this
->
connectionMock
=
$this
->
createMock
(
Connection
::
class
);
$this
->
connectionMock
=
$this
->
createMock
(
Connection
::
class
);
$this
->
connectionMock
->
method
(
'fetchAllAssociative'
)
$this
->
connectionMock
->
method
(
'fetchAllAssociative'
)
->
willReturn
([[
1
]]);
->
willReturn
([[
1
]]);
$this
->
connectionMock
->
method
(
'executeUpdate'
)
$this
->
connectionMock
->
method
(
'executeUpdate'
)
->
willReturn
(
42
);
->
willReturn
(
42
);
$helperSet
=
ConsoleRunner
::
createHelperSet
(
$this
->
connectionMock
);
$application
=
new
Application
();
$this
->
command
->
setHelperSet
(
$helperSet
);
$application
->
add
(
new
RunSqlCommand
(
new
SingleConnectionProvider
(
$this
->
connectionMock
)));
$this
->
command
=
$application
->
find
(
'dbal:run-sql'
);
$this
->
commandTester
=
new
CommandTester
(
$this
->
command
);
}
}
public
function
testMissingSqlArgument
()
:
void
public
function
testMissingSqlArgument
()
:
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment