Completed
Push — master ( 5075c7...d6d8a1 )
by Elf
05:24
created

configureForCurrentRequest()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

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