ConfigurationMiddleware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 11 4
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2022 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Middleware;
14
15
use App\Utility\ApiConfigTrait;
16
use BEdita\WebTools\ApiClientProvider;
17
use Cake\Core\Configure;
18
use Psr\Http\Message\ResponseInterface;
19
use Psr\Http\Message\ServerRequestInterface;
20
use Psr\Http\Server\MiddlewareInterface;
21
use Psr\Http\Server\RequestHandlerInterface;
22
23
/**
24
 * Configuration middleware.
25
 *
26
 * Load configuration from API using cache.
27
 */
28
class ConfigurationMiddleware implements MiddlewareInterface
29
{
30
    use ApiConfigTrait;
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
36
    {
37
        if (Configure::check('API.apiBaseUrl')) {
38
            $identity = $request->getAttribute('identity');
39
            if ($identity && $identity->get('tokens')) {
40
                ApiClientProvider::getApiClient()->setupTokens($identity->get('tokens'));
41
            }
42
            $this->readApiConfig();
43
        }
44
45
        return $handler->handle($request);
46
    }
47
}
48