Completed
Push — master ( 415244...7ca2f0 )
by Elf
05:45
created

AppConfigServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 8 2
A configureDefaults() 0 18 4
B configureForRequest() 0 16 5
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class AppConfigServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application services.
11
     *
12
     * @return void
13
     */
14 1
    public function boot()
15
    {
16
        //
17 1
    }
18
19
    /**
20
     * Register the application services.
21
     *
22
     * @return void
23
     */
24 1
    public function register()
25
    {
26 1
        if (! $this->app->configurationIsCached()) {
27 1
            $this->configureDefaults();
28
        }
29
30 1
        $this->configureForRequest($this->app['request']);
31 1
    }
32
33
    /**
34
     * Configure app defaults.
35
     */
36 1
    protected function configureDefaults()
37
    {
38 1
        $config = $this->app['config'];
39
40
        // Append "app.domains"
41 1
        $config['app.domains'] = array_map(function ($value) {
42 1
            if (is_string($domain = parse_url($value, PHP_URL_HOST))) {
43
                if (str_contains($domain, '.')) {
44
                    return $domain;
45
                }
46
            }
47 1
        }, $config['support.url']);
48
49
        // Set "mail.from.name"
50 1
        if ($config['mail.from.name'] == 'Example') {
51 1
            $config['mail.from.name'] = $config['app.name'];
52
        }
53 1
    }
54
55
    /**
56
     * Configure app for the given request.
57
     *
58
     * @param  \Illuminate\Http\Request  $request
59
     */
60 1
    protected function configureForRequest($request)
61
    {
62 1
        $config = $this->app['config'];
63
64 1
        $identifier = array_search($request->getHost(), $config['app.domains']);
65
66
        // Configure the cookie domain
67 1
        if (! is_null($identifier) && $config->has('support.cookie_domain.'.$identifier)) {
68
            $config['session.domain'] = $config['support.cookie_domain.'.$identifier];
69
        }
70
71
        // Configure the auth defaults
72 1
        if (! is_null($identifier) && is_array($auth = $config['support.auth.'.$identifier])) {
73
            $config['auth.defaults'] = $auth;
74
        }
75 1
    }
76
}
77