1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\Laravel\Support; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
|
7
|
|
|
class SupportServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Register the service provider. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function register() |
15
|
|
|
{ |
16
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/support.php', 'support'); |
17
|
|
|
|
18
|
|
|
$this->setupConfiguration(); |
19
|
|
|
|
20
|
|
|
array_map([$this->app, 'register'], $this->getServiceProviders()); |
21
|
|
|
|
22
|
|
|
if ($this->app->runningInConsole()) { |
23
|
|
|
$this->publishes([ |
24
|
|
|
__DIR__.'/../config/support.php' => config_path('support.php'), |
25
|
|
|
], 'laravel-support'); |
26
|
|
|
|
27
|
|
|
$this->registerForConsole(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Setup app configuration. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
protected function setupConfiguration() |
37
|
|
|
{ |
38
|
|
|
if (! $this->app->configurationIsCached()) { |
39
|
|
|
$this->configureDefaults(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->configureForCurrentRequest(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Configure app defaults. |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
protected function configureDefaults() |
51
|
|
|
{ |
52
|
|
|
$config = $this->app['config']; |
53
|
|
|
|
54
|
|
|
// Append "app.domains" |
55
|
|
|
$config['app.domains'] = array_map(function ($value) { |
56
|
|
|
if (is_string($domain = parse_url($value, PHP_URL_HOST))) { |
57
|
|
|
if (str_contains($domain, '.')) { |
58
|
|
|
return $domain; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
}, $config['support.url']); |
62
|
|
|
|
63
|
|
|
// Set "mail.from.name" |
64
|
|
|
if ($config['mail.from.name'] == 'Example') { |
65
|
|
|
$config['mail.from.name'] = $config['app.name']; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Configure app for the current request. |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
protected function configureForCurrentRequest() |
75
|
|
|
{ |
76
|
|
|
$config = $this->app['config']; |
77
|
|
|
$request = $this->app['request']; |
78
|
|
|
|
79
|
|
|
$identifier = array_search($request->getHost(), $config['app.domains']); |
80
|
|
|
|
81
|
|
|
if ($identifier && $config->has('support.cookie_domain.'.$identifier)) { |
82
|
|
|
$config['session.domain'] = $config['support.cookie_domain.'.$identifier]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($identifier && is_array($auth = $config['support.auth.'.$identifier])) { |
86
|
|
|
$config['auth.defaults'] = $auth; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get service providers to be registered. |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
protected function getServiceProviders() |
96
|
|
|
{ |
97
|
|
|
$providers = []; |
98
|
|
|
|
99
|
|
|
if ($this->app->isLocal()) { |
100
|
|
|
array_push( |
101
|
|
|
$providers, |
102
|
|
|
\Barryvdh\Debugbar\ServiceProvider::class |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
if ($this->app->runningInConsole()) { |
106
|
|
|
array_push( |
107
|
|
|
$providers, |
108
|
|
|
\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ($this->app->runningInConsole()) { |
114
|
|
|
array_push( |
115
|
|
|
$providers, |
116
|
|
|
\Laravel\Tinker\TinkerServiceProvider::class, |
117
|
|
|
\Spatie\Backup\BackupServiceProvider::class |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $providers; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Register for console. |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
protected function registerForConsole() |
130
|
|
|
{ |
131
|
|
|
$this->commands([ |
132
|
|
|
Console\Commands\AssetsVersion::class, |
133
|
|
|
Console\Commands\GenerateIdeHelpers::class, |
134
|
|
|
Console\Commands\GenerateInt2stringCharacters::class, |
135
|
|
|
]); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|