webnet-fr /
database-anonymizer
| 1 | <?php |
||
| 2 | |||
| 3 | namespace WebnetFr\DatabaseAnonymizer\Command; |
||
| 4 | |||
| 5 | use Symfony\Component\Console\Command\Command; |
||
| 6 | use Symfony\Component\Console\Input\InputInterface; |
||
| 7 | use Symfony\Component\Console\Input\InputOption; |
||
| 8 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 9 | use WebnetFr\DatabaseAnonymizer\ConfigGuesser\ConfigGuesser; |
||
| 10 | use WebnetFr\DatabaseAnonymizer\ConfigGuesser\ConfigWriter; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @author Vlad Riabchenko <[email protected]> |
||
| 14 | */ |
||
| 15 | class GuessConfigCommand extends Command |
||
| 16 | { |
||
| 17 | use AnonymizeCommandTrait; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var ConfigGuesser |
||
| 21 | */ |
||
| 22 | private $configGuesser; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var ConfigWriter |
||
| 26 | */ |
||
| 27 | private $configWriter; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param ConfigGuesser $configGuesser |
||
| 31 | * @param ConfigWriter $configWriter |
||
| 32 | */ |
||
| 33 | public function __construct(ConfigGuesser $configGuesser, ConfigWriter $configWriter) |
||
| 34 | { |
||
| 35 | parent::__construct(); |
||
| 36 | |||
| 37 | $this->configGuesser = $configGuesser; |
||
| 38 | $this->configWriter = $configWriter; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritdoc} |
||
| 43 | */ |
||
| 44 | protected function configure() |
||
| 45 | { |
||
| 46 | $this->setName('webnet-fr:anonymizer:guess-config') |
||
| 47 | ->setDescription('Guess anonymizer configuration.') |
||
| 48 | ->setHelp('Guess and dump anonymizer configuration.') |
||
| 49 | ->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'Dump to specified file.') |
||
| 50 | ->addOption('url', 'U', InputOption::VALUE_REQUIRED, 'Database connection string.') |
||
| 51 | ->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Database type.') |
||
| 52 | ->addOption('host', 'H', InputOption::VALUE_REQUIRED, 'Database host.') |
||
| 53 | ->addOption('port', 'P', InputOption::VALUE_REQUIRED, 'Database port.') |
||
| 54 | ->addOption('database', 'd', InputOption::VALUE_REQUIRED, 'Database name.') |
||
| 55 | ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'User.') |
||
| 56 | ->addOption('password', 'p', InputOption::VALUE_REQUIRED, 'Password.') |
||
| 57 | ; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 64 | { |
||
| 65 | $connection = $this->getConnectionFromInput($input); |
||
| 66 | |||
| 67 | $hints = $this->configGuesser::guess($connection); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 68 | $config = $this->configWriter->write($hints); |
||
| 69 | |||
| 70 | $file = $input->getOption('file'); |
||
| 71 | if ($file) { |
||
| 72 | \file_put_contents($file, $config); |
||
| 73 | } else { |
||
| 74 | $output->write($config); |
||
| 75 | } |
||
| 76 | |||
| 77 | return 0; |
||
| 78 | } |
||
| 79 | } |
||
| 80 |