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

ConfigServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 0
cts 33
cp 0
rs 10
c 0
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 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