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

ProcessCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace SfCod\SocketIoBundle\Command;
4
5
use Psr\Log\LoggerInterface;
6
use SfCod\SocketIoBundle\Service\Broadcast;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Class ProcessCommand
14
 * Run this daemon for listen socketio. Don't forget about run npm install in the folder "server".
15
 *
16
 * @package yiicod\socketio\commands
17
 */
18
class ProcessCommand extends Command
19
{
20
    /**
21
     * @var LoggerInterface
22
     */
23
    protected $logger;
24
25
    /**
26
     * @var Broadcast
27
     */
28
    protected $broadcast;
29
30
    /**
31
     * ProcessCommand constructor.
32
     *
33
     * @param Broadcast $broadcast
34
     */
35
    public function __construct(Broadcast $broadcast)
36
    {
37
        $this->broadcast = $broadcast;
38
39
        parent::__construct();
40
    }
41
42
    /**
43
     * Configure command
44
     */
45
    protected function configure()
46
    {
47
        parent::configure();
48
49
        $this->setName('socket-io:process')
50
            ->setDescription('Starts socket-io process.')
51
            ->addOption('handler', null, InputArgument::OPTIONAL, 'Process handler class', null)
52
            ->addOption('data', null, InputArgument::OPTIONAL, 'Serialized handle data.', null);
53
    }
54
55
    /**
56
     * Execute command
57
     *
58
     * @param InputInterface $input
59
     * @param OutputInterface $output
60
     *
61
     * @return int|null|void
62
     */
63
    public function execute(InputInterface $input, OutputInterface $output)
64
    {
65
        $handler = $input->getOption('handler');
66
67
        $this->broadcast->process($handler, @unserialize($input->getOption('data')) ?? []);
68
    }
69
}
70