1
|
|
|
<?php |
2
|
|
|
namespace SeleniumSetup\Controller; |
3
|
|
|
|
4
|
|
|
use SeleniumSetup\Config\Config; |
5
|
|
|
use SeleniumSetup\Config\ConfigFactory; |
6
|
|
|
use SeleniumSetup\Environment; |
7
|
|
|
use SeleniumSetup\SeleniumSetup; |
8
|
|
|
use SeleniumSetup\Service\StartServerService; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
class StartServer extends Command |
16
|
|
|
{ |
17
|
|
|
const CLI_COMMAND = 'start'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Configure the command options. |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
protected function configure() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$defaultName = basename(Config::DEFAULT_CONFIGURATION_FILENAME, '.json'); |
27
|
|
|
|
28
|
|
|
$this |
29
|
|
|
->setName(self::CLI_COMMAND) |
30
|
|
|
->setDescription('Start Selenium Server setup with all supported drivers attached to it.') |
31
|
|
|
->addArgument('name', InputArgument::OPTIONAL, 'The instance name.', $defaultName) |
32
|
|
|
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'The config path.'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the command. |
37
|
|
|
* |
38
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
39
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
43
|
|
|
{ |
44
|
|
|
$configFilePath = null; |
45
|
|
|
|
46
|
|
|
if ($input->getArgument('name')) { |
47
|
|
|
$configFilePath = SeleniumSetup::$APP_CONF_PATH . DIRECTORY_SEPARATOR . $input->getArgument('name') . '.json'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($input->getOption('config')) { |
51
|
|
|
$configFilePath = realpath($input->getOption('config')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Prepare. |
55
|
|
|
$config = ConfigFactory::createFromConfigFile($configFilePath); |
56
|
|
|
$env = new Environment($config, $input, $output); |
57
|
|
|
|
58
|
|
|
$handler = new StartServerService($config, $env, $input, $output); |
59
|
|
|
|
60
|
|
|
if ($handler->test()) { |
61
|
|
|
if (!$env->isAdmin()) { |
62
|
|
|
$output->writeln('<comment>Running without elevated rights.</comment>'); |
63
|
|
|
} |
64
|
|
|
$output->writeln('<comment>Let\'s go ...</comment>'); |
65
|
|
|
$handler->handle(); |
66
|
|
|
} else { |
67
|
|
|
$output->writeln('<error>Missing required components. Please review your setup.</error>'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
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.