|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gitamin\Providers; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
use Gitamin\Config\Repository; |
|
16
|
|
|
use Gitamin\Facades\Setting; |
|
17
|
|
|
use Gitamin\Models\Setting as SettingModel; |
|
18
|
|
|
use Illuminate\Support\ServiceProvider; |
|
19
|
|
|
|
|
20
|
|
|
class ConfigServiceProvider extends ServiceProvider |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Boot the service provider. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function boot() |
|
26
|
|
|
{ |
|
27
|
|
|
$appDomain = $appLocale = $appTimezone = null; |
|
28
|
|
|
|
|
29
|
|
|
try { |
|
30
|
|
|
// Get app custom configuration. |
|
31
|
|
|
$appDomain = Setting::get('app_domain'); |
|
32
|
|
|
$appLocale = Setting::get('app_locale'); |
|
33
|
|
|
$appTimezone = Setting::get('app_timezone'); |
|
34
|
|
|
|
|
35
|
|
|
// Setup Cors. |
|
36
|
|
|
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins'); |
|
|
|
|
|
|
37
|
|
|
$allowedOrigins[] = Setting::get('app_domain'); |
|
38
|
|
|
|
|
39
|
|
|
// Add our allowed domains too. |
|
40
|
|
|
if ($allowedDomains = Setting::get('allowed_domains')) { |
|
41
|
|
|
$domains = explode(',', $allowedDomains); |
|
42
|
|
|
foreach ($domains as $domain) { |
|
43
|
|
|
$allowedOrigins[] = $domain; |
|
44
|
|
|
} |
|
45
|
|
|
} else { |
|
46
|
|
|
$allowedOrigins[] = $this->app->config->get('app.url'); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins); |
|
|
|
|
|
|
50
|
|
|
} catch (Exception $e) { |
|
51
|
|
|
// Don't throw any errors, we may not be setup yet. |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Override default app values. |
|
55
|
|
|
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url')); |
|
|
|
|
|
|
56
|
|
|
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale')); |
|
|
|
|
|
|
57
|
|
|
$this->app->config->set('gitamin.timezone', $appTimezone ?: $this->app->config->get('gitamin.timezone')); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
// Set custom lang. |
|
60
|
|
|
$this->app->translator->setLocale($appLocale); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Register the service provider. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function register() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->app->bindShared('setting', function () { |
|
69
|
|
|
return new Repository(new SettingModel()); |
|
70
|
|
|
}); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: