Completed
Push — master ( d3d242...9eb338 )
by Elf
05:07
created

AppConfigServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 59
ccs 22
cts 29
cp 0.7586
rs 10
c 1
b 0
f 0
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\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class AppConfigServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Register the application services.
11
     *
12
     * @return void
13
     */
14 1
    public function register()
15
    {
16 1
        if (! $this->app->configurationIsCached()) {
17 1
            $this->configureDefaults();
18 1
        }
19
20 1
        $this->configureForCurrentRequest();
21 1
    }
22
23
    /**
24
     * Configure app defaults.
25
     */
26 1
    protected function configureDefaults()
27
    {
28 1
        $config = $this->app['config'];
29
30
        // Append "app.domains"
31 1
        $config['app.domains'] = array_map(function ($value) {
32 1
            if (is_string($domain = parse_url($value, PHP_URL_HOST))) {
33
                if (str_contains($domain, '.')) {
34
                    return $domain;
35
                }
36
            }
37 1
        }, $config['support.url']);
38
39
        // Set "mail.from.name"
40 1
        if ($config['mail.from.name'] == 'Example') {
41 1
            $config['mail.from.name'] = $config['app.name'];
42 1
        }
43 1
    }
44
45
    /**
46
     * Configure app for the current request.
47
     */
48 1
    protected function configureForCurrentRequest()
49
    {
50 1
        $config = $this->app['config'];
51 1
        $request = $this->app['request'];
52
53 1
        $identifier = array_search($request->getHost(), $config['app.domains']);
54
55
        // Configure the cookie domain
56 1
        if (! is_null($identifier) && $config->has('support.cookie_domain.'.$identifier)) {
57
            $config['session.domain'] = $config['support.cookie_domain.'.$identifier];
58
        }
59
60
        // Configure the auth defaults
61 1
        if (! is_null($identifier) && is_array($auth = $config['support.auth.'.$identifier])) {
62
            $config['auth.defaults'] = $auth;
63
        }
64 1
    }
65
}
66