Completed
Push — master ( c3f7f6...458bfd )
by Changwan
02:39
created

CorsServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Service\NeomerxCors;
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\Config\Contracts\Config;
11
use Wandu\DI\ContainerInterface;
12
use Wandu\DI\ServiceProviderInterface;
13
14
class CorsServiceProvider implements ServiceProviderInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function register(ContainerInterface $app)
20
    {
21
        $app->bind(Settings::class)->after(function (Settings $settings, Config $config) {
22
            $settings->setServerOrigin($config->get('cors.server_origin'));
23
            $settings->setRequestAllowedOrigins($config->get('cors.allowed_origins', []));
24
            $settings->setRequestAllowedMethods($config->get('cors.allowed_methods', []));
25
            $settings->setRequestAllowedHeaders($config->get('cors.allowed_headers', []));
26
        });
27
        $app->alias(AnalysisStrategyInterface::class, Settings::class);
28
        $app->alias(SettingsStrategyInterface::class, Settings::class);
29
30
        $app->bind(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