Completed
Push — master ( cc84b4...34fefe )
by Sébastien
03:30
created

PjbServerStartCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 11
cts 11
cp 1
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PjbServer\Tools\Console\Command;
4
5
use PjbServer\Tools\StandaloneServer;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
12
13
class PjbServerStartCommand extends Command
14
{
15
    /**
16
     * @var StandaloneServer
17
     */
18
    protected $server;
19
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 1
    protected function configure()
25
    {
26 1
        $this->setName('pjbserver:start')
27 1
             ->setDescription(
28
                 'Start the standalone pjb server (java)'
29 1
               )
30 1
            ->addArgument(
31 1
                'config-file',
32 1
                InputArgument::REQUIRED,
33
                'Configuration file, see ./dist/pjbserver.config.php.dist'
34 1
            )
35
36 1
             ->setHelp(<<<EOT
37
Start the php java bridge server in the background.
38
EOT
39 1
        );
40 1
    }
41
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $file = $input->getArgument('config-file');
45
46
        // Test if config file exists
47
        if (!file_exists($file) || !is_readable($file)) {
48
            $msg = "Configuration file '$file' does not exists or is not readable'";
49
            throw new \InvalidArgumentException($msg);
50
        }
51
        $params = include($file);
52
        $port = $params['port'];
53
54
        $config = new StandaloneServer\Config($params);
55
56
        $this->server = new StandaloneServer($config);
57
        $this->server->start();
58
59
        $output->write("Server successfully started on port $port" . PHP_EOL);
60
    }
61
}
62