Middleware::loadMiddleware()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.7333
1
<?php
2
3
namespace SeedApp;
4
5
use Slim\App;
6
7
class Middleware
8
{
9
    protected $app;
10
11
    public function __construct(App $app)
12
    {
13
        $this->app = $app;
14
    }
15
16
    public function loadMiddleware()
17
    {
18
        $this->app->add(function ($request, $response, $next) {
19
            $response = $response->
20
                withAddedHeader('Access-Control-Allow-Origin', $request->getHeader('Origin'))->
21
                withAddedHeader('Access-Control-Allow-Credentials', 'true')->
22
                withAddedHeader('Access-Control-Expose-Headers', 'X-TOTAL-COUNT')->
23
                withAddedHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')->
24
                withAddedHeader(
25
                    'Access-Control-Allow-Headers',
26
                    'X-XSRF-TOKEN, Content-Type, X-REQUEST-TOTAL-COUNT, Authorization'
27
                );
28
            $response = $next($request, $response);
29
            return $response;
30
        });
31
32
        $this->app->add(function ($request, $response, $next) {
33
            $response = $response->
34
                withHeader('Content-Type', 'application/vnd.seedapp.v1+json');
35
36
            $response = $next($request, $response);
37
            return $response;
38
        });
39
    }
40
}
41