1
|
|
|
<?php |
2
|
|
|
namespace SeleniumSetup; |
3
|
|
|
|
4
|
|
|
use SeleniumSetup\Controller\StartServer; |
5
|
|
|
use Symfony\Component\Console\Application; |
6
|
|
|
use Symfony\Component\Console\ConsoleEvents; |
7
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
8
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
9
|
|
|
|
10
|
|
|
class SeleniumSetup |
11
|
|
|
{ |
12
|
|
|
const APP_NAME = 'Selenium Setup'; |
13
|
|
|
const APP_VERSION = '4.0.0'; |
14
|
|
|
const APP_DEFAULT_COMMAND = 'list'; |
15
|
|
|
public static $APP_ROOT_PATH; |
16
|
|
|
public static $APP_CONF_PATH; |
17
|
|
|
public static $APP_PROCESS_ENV; |
18
|
|
|
|
19
|
|
|
const SSL_CERT_FILENAME = 'cacert.pem'; |
20
|
|
|
const DEFAULT_LOCK_FILENAME = 'selenium-servers.lock'; |
21
|
|
|
|
22
|
|
|
public static $BANNER = <<<'BANNER' |
23
|
|
|
____ ___ |
24
|
|
|
/\ _`\ /\_ \ __ |
25
|
|
|
\ \,\L\_\ __\//\ \ __ ___ /\_\ __ __ ___ ___ |
26
|
|
|
\/_\__ \ /'__`\\ \ \ /'__`\/' _ `\/\ \/\ \/\ \ /' __` __`\ |
27
|
|
|
/\ \L\ \/\ __/ \_\ \_/\ __//\ \/\ \ \ \ \ \_\ \/\ \/\ \/\ \ |
28
|
|
|
\ `\____\ \____\/\____\ \____\ \_\ \_\ \_\ \____/\ \_\ \_\ \_\ |
29
|
|
|
\/_____/\/____/\/____/\/____/\/_/\/_/\/_/\/___/ \/_/\/_/\/_/ |
30
|
|
|
Selenium Environment on Windows, Linux and Mac |
31
|
|
|
by Bogdan Anton and contributors. |
32
|
|
|
|
33
|
|
|
BANNER; |
34
|
|
|
|
35
|
|
|
public function __construct() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
self::$APP_ROOT_PATH = realpath(dirname(__FILE__) . '/../'); |
38
|
|
|
self::$APP_CONF_PATH = realpath(dirname(__FILE__) . '/../config/'); |
39
|
|
|
self::$APP_PROCESS_ENV = array_merge($_SERVER, $_ENV); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function run() |
43
|
|
|
{ |
44
|
|
|
$console = new Application(self::APP_NAME, self::APP_VERSION); |
45
|
|
|
$console->setDefaultCommand(self::APP_DEFAULT_COMMAND); |
46
|
|
|
|
47
|
|
|
$dispatcher = new EventDispatcher(); |
48
|
|
|
$dispatcher->addListener(ConsoleEvents::COMMAND, function(ConsoleCommandEvent $event) { |
49
|
|
|
// get the input instance |
50
|
|
|
// $input = $event->getInput(); |
|
|
|
|
51
|
|
|
|
52
|
|
|
// get the output instance |
53
|
|
|
$output = $event->getOutput(); |
54
|
|
|
|
55
|
|
|
// get the command to be executed |
56
|
|
|
$command = $event->getCommand(); |
57
|
|
|
|
58
|
|
|
// write something about the command |
59
|
|
|
//$output->writeln(sprintf('Before running command <info>%s</info>', $command->getName())); |
|
|
|
|
60
|
|
|
if ($command->getName() == StartServer::CLI_COMMAND) { |
61
|
|
|
$output->write(self::$BANNER); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// get the application |
65
|
|
|
// $application = $command->getApplication(); |
|
|
|
|
66
|
|
|
}); |
67
|
|
|
$console->setDispatcher($dispatcher); |
68
|
|
|
|
69
|
|
|
$console->addCommands([ |
70
|
|
|
new Controller\StartServer, |
71
|
|
|
new Controller\StopServer, |
72
|
|
|
new Controller\ListServers, |
73
|
|
|
new Controller\RegisterServer, |
74
|
|
|
]); |
75
|
|
|
|
76
|
|
|
$console->run(); |
77
|
|
|
} |
78
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: