|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
|
|
7
|
|
|
class ConfigServiceProvider extends ServiceProvider |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Bootstrap the application services. |
|
11
|
|
|
* |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
1 |
|
public function boot() |
|
15
|
|
|
{ |
|
16
|
|
|
// |
|
17
|
1 |
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Register the application services. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function register() |
|
25
|
|
|
{ |
|
26
|
1 |
|
if (! $this->app->configurationIsCached()) { |
|
27
|
1 |
|
$this->configureDefaults(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
$this->configureForRequest($this->app['request']); |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Configure defaults. |
|
35
|
|
|
*/ |
|
36
|
1 |
|
protected function configureDefaults() |
|
37
|
|
|
{ |
|
38
|
1 |
|
$this->appendAppDomainsConfig(); |
|
39
|
|
|
|
|
40
|
1 |
|
$this->setMailConfig(); |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Append "app.domains" config. |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function appendAppDomainsConfig() |
|
47
|
|
|
{ |
|
48
|
1 |
|
$this->app['config']['app.domains'] = array_map(function ($value) { |
|
49
|
1 |
|
if (is_string($domain = parse_url($value, PHP_URL_HOST))) { |
|
50
|
|
|
if (str_contains($domain, '.')) { |
|
51
|
|
|
return $domain; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
1 |
|
}, $this->app['config']['holly.url']); |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Set "mail" config. |
|
59
|
|
|
*/ |
|
60
|
1 |
|
protected function setMailConfig() |
|
61
|
|
|
{ |
|
62
|
1 |
|
if (str_contains($username = $this->app['config']['mail.username'], '@') && |
|
63
|
1 |
|
$this->app['config']['mail.from.address'] == '[email protected]') { |
|
64
|
|
|
$this->app['config']['mail.from.address'] = $username; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
if ($this->app['config']['mail.from.name'] == 'Example') { |
|
68
|
1 |
|
$this->app['config']['mail.from.name'] = $this->app['config']['app.name']; |
|
69
|
|
|
} |
|
70
|
1 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Configure app for the request. |
|
74
|
|
|
* |
|
75
|
|
|
* @param \Illuminate\Http\Request $request |
|
76
|
|
|
*/ |
|
77
|
1 |
|
protected function configureForRequest($request) |
|
78
|
|
|
{ |
|
79
|
1 |
|
$domain = $request->getHost(); |
|
80
|
1 |
|
$identifier = array_search($domain, $this->app['config']['app.domains']); |
|
81
|
|
|
|
|
82
|
|
|
// Configure the cookie domain |
|
83
|
1 |
|
if (! is_null($identifier) && $this->app['config']->has('holly.cookie_domain.'.$identifier)) { |
|
84
|
|
|
$this->app['config']['session.domain'] = $this->app['config']['holly.cookie_domain.'.$identifier]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Configure the auth defaults |
|
88
|
1 |
|
if (! is_null($identifier) && is_array($auth = $this->app['config']['holly.auth.'.$identifier])) { |
|
89
|
|
|
$this->app['config']['auth.defaults'] = $auth; |
|
90
|
|
|
} |
|
91
|
1 |
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|