ChatServerCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 13
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace AppBundle\Command;
4
5
use AppBundle\Server\Chat;
6
use Ratchet\Http\HttpServer;
7
use Ratchet\Server\IoServer;
8
use Ratchet\WebSocket\WsServer;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Chat Server Command.
15
 */
16
class ChatServerCommand extends ContainerAwareCommand
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function configure()
22
    {
23
        $this
24
            ->setName('afsy:app:chat-server')
25
            ->setDescription('Start chat server');
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        // Initialize
34
        $wsConfig = $this->getContainer()->getParameter('afsy_chat.websocket');
35
36
        // Create server and run it!
37
        $server = IoServer::factory(
38
            new HttpServer(new WsServer(new Chat())),
39
            $wsConfig['port'],
40
            $wsConfig['host']
41
        );
42
        echo sprintf('Run server on %s:%s'."\n", $wsConfig['host'], $wsConfig['port']);
43
        $server->run();
44
    }
45
}
46