Completed
Push — master ( a0f59b...05c571 )
by Elf
05:11
created

AppConfigServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 57
ccs 20
cts 20
cp 1
rs 10
wmc 11
lcom 1
cbo 1

3 Methods

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