PhpServerCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    public function __construct(Worker $worker)
28
    {
29
        $this->worker = $worker;
30
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Configure command.
36
     */
37
    protected function configure()
38
    {
39
        parent::configure();
40
41
        $this->setName('socket-io:php-server')
42
            ->setDescription('Work php server.');
43
    }
44
45
    /**
46
     * Execute command.
47
     *
48
     * @return int|void|null
49
     *
50
     * @throws \Exception
51
     */
52
    public function execute(InputInterface $input, OutputInterface $output)
53
    {
54
        $io = new SymfonyStyle($input, $output);
55
56
        $io->success(sprintf('Worker daemon has been started.'));
57
58
        while (true) {
59
            $this->worker->predis($io);
60
        }
61
    }
62
}
63