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
|
|
|
|