TInit   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 26
c 2
b 0
f 1
dl 0
loc 108
ccs 17
cts 17
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEnabled() 0 3 1
A init() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Middlewares\Reuse;
6
7
use Nymfonya\Component\Config;
8
use Nymfonya\Component\Container;
9
use Nymfonya\Component\Http\Request;
10
use Nymfonya\Component\Http\Response;
11
use Nymfonya\Component\Http\Kernel;
12
use Monolog\Logger;
13
14
trait TInit
15
{
16
17
    /**
18
     * kernel
19
     *
20
     * @var Kernel
21
     */
22
    protected $kernel;
23
24
    /**
25
     * config
26
     *
27
     * @var Config
28
     */
29
    protected $config;
30
31
    /**
32
     * config middlewares params
33
     *
34
     * @var array
35
     */
36
    protected $configParams;
37
38
    /**
39
     * request
40
     *
41
     * @var Request
42
     */
43
    protected $request;
44
45
    /**
46
     * request headers
47
     *
48
     * @var array
49
     */
50
    protected $headers;
51
52
    /**
53
     * request
54
     *
55
     * @var Response
56
     */
57
    protected $response;
58
59
    /**
60
     * logger
61
     *
62
     * @var Logger
63
     */
64
    protected $logger;
65
66
    /**
67
     * enabled set from middlewares params
68
     *
69
     * @var Boolean
70
     */
71
    protected $enabled;
72
73
    /**
74
     * exclude requirement
75
     *
76
     * @var array
77
     */
78
    protected $exclude;
79
80
    /**
81
     * uri prefix to match if middleware is required
82
     *
83
     * @var string
84
     */
85
    protected $prefix;
86
87
    /**
88
     * init minimal requirements settings
89
     *
90
     * @param array $container
91
     * @return void
92
     */
93 4
    protected function init(Container $container)
94
    {
95 4
        $this->kernel = $container->getService(
96 4
            Kernel::class
97
        );
98 4
        $this->config = $container->getService(
99 4
            Config::class
100
        );
101 4
        $this->configParams = $this->config->getSettings(
102 4
            Config::_MIDDLEWARES
103 4
        )[get_called_class()];
104 4
        $this->request = $container->getService(Request::class);
105 4
        $this->headers = $this->request->getHeaders();
106 4
        $this->response = $container->getService(Response::class);
107 4
        $this->logger = $container->getService(\Monolog\Logger::class);
108 4
        $this->enabled = $this->configParams['enabled'];
109 4
        $this->prefix = $this->configParams['prefix'];
110 4
        $this->exclude = $this->configParams['exclude'];
111
    }
112
113
    /**
114
     * set enabled from $enable
115
     *
116
     * @param boolean $enable
117
     * @return void
118
     */
119 7
    protected function setEnabled(bool $enable)
120
    {
121 7
        $this->enabled = $enable;
122
    }
123
}
124