Completed
Push — develop ( 059b46...8f56e3 )
by Michele
02:21
created

UpdateMode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 7
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zanzara\UpdateMode;
6
7
use Psr\Container\ContainerInterface;
8
use React\EventLoop\LoopInterface;
9
use Zanzara\Config;
10
use Zanzara\Context;
11
use Zanzara\Telegram\Telegram;
12
use Zanzara\Telegram\Type\Update;
13
use Zanzara\Zanzara;
14
use Zanzara\ZanzaraLogger;
15
use Zanzara\ZanzaraMapper;
16
17
/**
18
 *
19
 */
20
abstract class UpdateMode
21
{
22
23
    /**
24
     * @var ContainerInterface
25
     */
26
    protected $container;
27
28
    /**
29
     * @var Zanzara
30
     */
31
    protected $zanzara;
32
33
    /**
34
     * @var Telegram
35
     */
36
    protected $telegram;
37
38
    /**
39
     * @var Config
40
     */
41
    protected $config;
42
43
    /**
44
     * @var ZanzaraLogger
45
     */
46
    protected $logger;
47
48
    /**
49
     * @var LoopInterface
50
     */
51
    protected $loop;
52
53
    /**
54
     * @var ZanzaraMapper
55
     */
56
    protected $zanzaraMapper;
57
58
    /**
59
     * @param ContainerInterface $container
60
     * @param Zanzara $zanzara
61
     * @param Telegram $telegram
62
     * @param Config $config
63
     * @param ZanzaraLogger $logger
64
     * @param LoopInterface $loop
65
     * @param ZanzaraMapper $zanzaraMapper
66
     */
67
    public function __construct(ContainerInterface $container, Zanzara $zanzara, Telegram $telegram, Config $config,
68
                                ZanzaraLogger $logger, LoopInterface $loop, ZanzaraMapper $zanzaraMapper)
69
    {
70
        $this->container = $container;
71
        $this->zanzara = $zanzara;
72
        $this->telegram = $telegram;
73
        $this->config = $config;
74
        $this->logger = $logger;
75
        $this->loop = $loop;
76
        $this->zanzaraMapper = $zanzaraMapper;
77
    }
78
79
    public abstract function run();
80
81
    /**
82
     * @param Update $update
83
     */
84
    protected function processUpdate(Update $update)
85
    {
86
        $update->detectUpdateType();
87
        $context = new Context($update, $this->container);
88
        $listeners = $this->zanzara->resolve($update);
89
        foreach ($listeners as $listener) {
90
            $middlewareTip = $listener->getTip();
91
            $middlewareTip($context);
92
        }
93
    }
94
95
}
96