|
1
|
|
|
<?php |
|
2
|
|
|
namespace SeleniumSetup\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use SeleniumSetup\Config\ConfigFactory; |
|
5
|
|
|
use SeleniumSetup\Environment; |
|
6
|
|
|
use SeleniumSetup\Service\RegisterServerService; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
class RegisterServer extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
const CLI_COMMAND = 'register'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Configure the command options. |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function configure() |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$this |
|
25
|
|
|
->setName(self::CLI_COMMAND) |
|
26
|
|
|
->setDescription('Register a SeleniumSetup server instance.') |
|
27
|
|
|
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'The config path.') |
|
28
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Instance name.') |
|
29
|
|
|
->addArgument('port', InputArgument::REQUIRED, 'Instance port.'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Execute the command. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
36
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
40
|
|
|
{ |
|
41
|
|
|
$configFilePath = null; |
|
42
|
|
|
|
|
43
|
|
|
if ($input->getOption('config')) { |
|
44
|
|
|
$configFilePath = realpath($input->getOption('config')); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// Prepare. |
|
48
|
|
|
$config = ConfigFactory::createFromConfigFile($configFilePath); |
|
49
|
|
|
$env = new Environment($config, $input, $output); |
|
50
|
|
|
|
|
51
|
|
|
$handler = new RegisterServerService($config, $env, $input, $output); |
|
52
|
|
|
$handler->handle(); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.