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

CorsPsr7ServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 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