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

CorsServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 20 2
A boot() 0 3 1
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