gggeek /
db-3v4l
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace Db3v4l\Command; |
||
| 4 | |||
| 5 | use Db3v4l\API\Interfaces\SqlExecutor\Forked\ShellExecutor; |
||
| 6 | use Db3v4l\Core\SqlExecutor\Forked\NativeClient; |
||
| 7 | use Db3v4l\Service\DatabaseConfigurationManager; |
||
| 8 | use Db3v4l\Service\SqlExecutorFactory; |
||
| 9 | use Symfony\Component\Console\Input\InputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 10 | use Symfony\Component\Console\Input\InputOption; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | |||
| 13 | class SqlShell extends BaseCommand |
||
|
0 ignored issues
–
show
|
|||
| 14 | { |
||
| 15 | protected static $defaultName = 'db3v4l:sql:shell'; |
||
| 16 | |||
| 17 | /** @var DatabaseConfigurationManager $dbConfigurationManager */ |
||
|
0 ignored issues
–
show
|
|||
| 18 | protected $dbConfigurationManager; |
||
| 19 | /** @var SqlExecutorFactory $executorFactory */ |
||
|
0 ignored issues
–
show
|
|||
| 20 | protected $executorFactory; |
||
| 21 | |||
| 22 | public function __construct( |
||
|
0 ignored issues
–
show
|
|||
| 23 | DatabaseConfigurationManager $dbConfigurationManager, |
||
| 24 | SqlExecutorFactory $executorFactory) |
||
|
0 ignored issues
–
show
|
|||
| 25 | { |
||
|
0 ignored issues
–
show
|
|||
| 26 | $this->dbConfigurationManager = $dbConfigurationManager; |
||
| 27 | $this->executorFactory = $executorFactory; |
||
| 28 | |||
| 29 | parent::__construct(); |
||
| 30 | } |
||
| 31 | |||
| 32 | protected function configure() |
||
|
0 ignored issues
–
show
|
|||
| 33 | { |
||
| 34 | $this |
||
| 35 | ->setDescription('Connects to one of the configured database instances, using the appropriate native sql client') |
||
| 36 | ->addOption('instance', 'i', InputOption::VALUE_REQUIRED, 'The instance to connect to', null) |
||
| 37 | ->addOption('database', 'd', InputOption::VALUE_REQUIRED, 'The name of an existing database to use') |
||
|
0 ignored issues
–
show
|
|||
| 38 | ; |
||
| 39 | } |
||
| 40 | |||
| 41 | protected function execute(InputInterface $input, OutputInterface $output) |
||
|
0 ignored issues
–
show
|
|||
| 42 | { |
||
| 43 | $instanceName = $input->getOption('instance'); |
||
| 44 | $dbName = $input->getOption('database'); |
||
| 45 | |||
| 46 | if ($instanceName == null) { |
||
| 47 | throw new \Exception("Please provide an instance name"); |
||
| 48 | } |
||
| 49 | |||
| 50 | $dbConnectionSpec = $this->dbConfigurationManager->getInstanceConfiguration($instanceName); |
||
| 51 | if ($dbName != '') { |
||
| 52 | $dbConnectionSpec['dbname'] = $dbName; |
||
| 53 | } |
||
| 54 | $executor = $this->executorFactory->createForkedExecutor($instanceName, $dbConnectionSpec, NativeClient::EXECUTION_STRATEGY, false); |
||
| 55 | |||
| 56 | if (! $executor instanceof ShellExecutor) { |
||
| 57 | throw new \Exception("Can not start an interactive shell for databases of type '{$dbConnectionSpec['vendor']}'"); |
||
| 58 | } |
||
| 59 | |||
| 60 | $process = $executor->getExecuteShellProcess(); |
||
| 61 | |||
| 62 | $process->setTty(true); |
||
| 63 | $process->run(); |
||
| 64 | |||
| 65 | return $process->getExitCode(); |
||
| 66 | } |
||
| 67 | } |
||
| 68 |