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

AppConfigServiceProvider::configureDefaults()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
nc 2
nop 0
dl 0
loc 18
ccs 9
cts 12
cp 0.75
crap 4.25
rs 9.2
c 1
b 0
f 0
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