Completed
Push — master ( c7ef3c...356585 )
by Alexey
11s
created

PhpServerCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 7 1
A execute() 0 10 2
1
<?php
2
3
namespace SfCod\SocketIoBundle\Command;
4
5
use SfCod\SocketIoBundle\Service\Worker;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Style\SymfonyStyle;
10
11
/**
12
 * Class WorkSocketIoCommand
13
 * Socketio worker. Use pm2 (http://pm2.keymetrics.io/) for fork command.
14
 *
15
 * @package yiicod\socketio\commands
16
 */
17
class PhpServerCommand extends Command
18
{
19
    /**
20
     * @var Worker
21
     */
22
    protected $worker;
23
24
    /**
25
     * PhpServerCommand constructor.
26
     *
27
     * @param Worker $worker
28
     */
29
    public function __construct(Worker $worker)
30
    {
31
        $this->worker = $worker;
32
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Configure command
38
     */
39
    protected function configure()
40
    {
41
        parent::configure();
42
43
        $this->setName('socket-io:php-server')
44
            ->setDescription('Work php server.');
45
    }
46
47
    /**
48
     * Execute command
49
     *
50
     * @param InputInterface $input
51
     * @param OutputInterface $output
52
     *
53
     * @return int|null|void
54
     *
55
     * @throws \Exception
56
     */
57
    public function execute(InputInterface $input, OutputInterface $output)
58
    {
59
        $io = new SymfonyStyle($input, $output);
60
61
        $io->success(sprintf('Worker daemon has been started.'));
62
63
        while (true) {
64
            $this->worker->predis($io);
65
        }
66
    }
67
}
68