Completed
Push — master ( e20120...0bdab5 )
by Haven
01:57
created

Guard::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace HavenShen\Slim\Cors;
4
5
class Guard
6
{
7
8
    public $settings;
9
10
    protected $response;
11
12 1
    public function __construct($settings = [])
13
    {
14 1
        $this->settings = array_merge([
15 1
            'Access-Control-Allow-Origin' => '*',
16
            'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS'
17
        ],$settings);
18 1
    }
19
20 1
    public function __invoke($request, $response, $next)
21
    {
22 1
        $this->response = $next($request, $response);
23 1
        foreach ($this->settings as $key => $value) {
24 1
            $this->response = $this->response->withAddedHeader($key, $value);
25
        }
26 1
        return $this->response;
27
    }
28
29 1
    public function getResponseHeradersOrigin()
30
    {
31 1
        return $this->response->getHeaderLine('Access-Control-Allow-Origin');
32
    }
33
}