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