Completed
Push — master ( dc7866...8155ff )
by Changwan
06:46
created

CorsPsr7ServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 33
rs 10
c 1
b 0
f 1
wmc 3
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 20 2
A boot() 0 3 1
1
<?php
2
namespace Wandu\DI\Providers\Neomerx;
3
4
use Neomerx\Cors\Analyzer;
5
use Neomerx\Cors\Contracts\AnalysisStrategyInterface;
6
use Neomerx\Cors\Contracts\AnalyzerInterface;
7
use Neomerx\Cors\Contracts\Strategies\SettingsStrategyInterface;
8
use Neomerx\Cors\Strategies\Settings;
9
use Psr\Log\LoggerInterface;
10
use Wandu\DI\ContainerInterface;
11
use Wandu\DI\ServiceProviderInterface;
12
use function Wandu\Foundation\config;
13
14
class CorsPsr7ServiceProvider implements ServiceProviderInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function register(ContainerInterface $app)
20
    {
21
        $app->bind(Settings::class)->after(function (Settings $settings) {
22
            $settings->setServerOrigin(config('neomerx.cors-psr7.server-origin'));
23
            $settings->setRequestAllowedOrigins(config('neomerx.cors-psr7.allowed-origins', []));
24
            $settings->setRequestAllowedMethods(config('neomerx.cors-psr7.allowed-methods', []));
25
            $settings->setRequestAllowedHeaders(config('neomerx.cors-psr7.allowed-headers', []));
26
        });
27
        $app->alias(AnalysisStrategyInterface::class, Settings::class);
28
        $app->alias(SettingsStrategyInterface::class, Settings::class);
29
30
        $app->closure(Analyzer::class, function (AnalysisStrategyInterface $strategy) {
31
            return Analyzer::instance($strategy);
32
        })->after(function (Analyzer $analyzer) use ($app) {
33
            if ($app->has(LoggerInterface::class)) {
34
                $analyzer->setLogger($app->get(LoggerInterface::class));
35
            }
36
        });
37
        $app->alias(AnalyzerInterface::class, Analyzer::class);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function boot(ContainerInterface $app)
44
    {
45
    }
46
}
47