1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\Providers; |
4
|
|
|
|
5
|
|
|
use config; |
6
|
|
|
use Thinktomorrow\Chief\Users\User; |
7
|
|
|
use Illuminate\Support\Facades\Blade; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
use Illuminate\Support\Facades\Validator; |
10
|
|
|
use Thinktomorrow\Chief\App\Console\Seed; |
11
|
|
|
use Thinktomorrow\Chief\Management\Register; |
12
|
|
|
use Thinktomorrow\Chief\App\Console\CreateAdmin; |
13
|
|
|
use Thinktomorrow\Squanto\SquantoServiceProvider; |
14
|
|
|
use Thinktomorrow\Chief\Pages\Console\GeneratePage; |
15
|
|
|
use Thinktomorrow\Chief\App\Console\CreateDeveloper; |
16
|
|
|
use Thinktomorrow\Chief\App\Console\RefreshDatabase; |
17
|
|
|
use Thinktomorrow\Chief\Settings\Console\SeedSettings; |
18
|
|
|
use Thinktomorrow\Squanto\SquantoManagerServiceProvider; |
19
|
|
|
use Thinktomorrow\Chief\Settings\SettingsServiceProvider; |
20
|
|
|
use Thinktomorrow\AssetLibrary\AssetLibraryServiceProvider; |
21
|
|
|
use Thinktomorrow\Chief\Authorization\Console\GenerateRoleCommand; |
22
|
|
|
use Thinktomorrow\Chief\Authorization\Console\GeneratePermissionCommand; |
23
|
|
|
|
24
|
|
|
class ChiefServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
public function boot() |
27
|
|
|
{ |
28
|
|
|
$this->registerChiefGuard(); |
29
|
|
|
|
30
|
|
|
$this->app['view']->addNamespace('squanto', __DIR__ . '/../../resources/views/vendor/squanto'); |
31
|
|
|
$this->app['view']->addNamespace('squanto', base_path() . '/resources/views/vendor/thinktomorrow/chief/vendor/squanto'); |
32
|
|
|
|
33
|
|
|
(new MacrosServiceProvider($this->app))->boot(); |
34
|
|
|
(new AuthServiceProvider($this->app))->boot(); |
35
|
|
|
(new EventServiceProvider($this->app))->boot(); |
36
|
|
|
(new SquantoServiceProvider($this->app))->boot(); |
37
|
|
|
(new SquantoManagerServiceProvider($this->app))->boot(); |
38
|
|
|
(new SettingsServiceProvider($this->app))->boot(); |
39
|
|
|
|
40
|
|
|
(new AssetLibraryServiceProvider($this->app))->boot(); |
41
|
|
|
|
42
|
|
|
// Project defaults |
43
|
|
|
(new ChiefProjectServiceProvider($this->app))->boot(); |
44
|
|
|
|
45
|
|
|
$this->loadRoutesFrom(__DIR__ . '/../routes.php'); |
46
|
|
|
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'chief'); |
47
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations'); |
48
|
|
|
$this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'chief'); |
49
|
|
|
|
50
|
|
|
$this->publishes([ |
51
|
|
|
__DIR__ . '/../../config/chief.php' => config_path('thinktomorrow/chief.php'), |
52
|
|
|
__DIR__ . '/../../config/chief-settings.php' => config_path('thinktomorrow/chief-settings.php'), |
53
|
|
|
], 'chief-config'); |
54
|
|
|
|
55
|
|
|
$this->publishes([ |
56
|
|
|
__DIR__ . '/../../public/chief-assets' => public_path('/chief-assets'), |
57
|
|
|
], 'chief-assets'); |
58
|
|
|
|
59
|
|
|
// Register commands |
60
|
|
|
if ($this->app->runningInConsole()) { |
61
|
|
|
$this->commands([ |
62
|
|
|
// Local development |
63
|
|
|
'command.chief:refresh', |
64
|
|
|
'command.chief:seed', |
65
|
|
|
|
66
|
|
|
// Project setup tools |
67
|
|
|
'command.chief:permission', |
68
|
|
|
'command.chief:role', |
69
|
|
|
'command.chief:admin', |
70
|
|
|
'command.chief:developer', |
71
|
|
|
'command.chief:page', |
72
|
|
|
'command.chief:settings', |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
// Bind our commands to the container |
76
|
|
|
$this->app->bind('command.chief:refresh', RefreshDatabase::class); |
77
|
|
|
$this->app->bind('command.chief:seed', Seed::class); |
78
|
|
|
$this->app->bind('command.chief:permission', GeneratePermissionCommand::class); |
79
|
|
|
$this->app->bind('command.chief:role', GenerateRoleCommand::class); |
80
|
|
|
$this->app->bind('command.chief:admin', CreateAdmin::class); |
81
|
|
|
$this->app->bind('command.chief:developer', CreateDeveloper::class); |
82
|
|
|
$this->app->bind('command.chief:settings', SeedSettings::class); |
83
|
|
|
$this->app->bind('command.chief:page', function ($app) { |
84
|
|
|
return new GeneratePage($app['files'], [ |
85
|
|
|
'base_path' => base_path() |
86
|
|
|
]); |
87
|
|
|
}); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
Blade::component('chief::back._layouts._partials.header', 'chiefheader'); |
91
|
|
|
Blade::component('chief::back._elements.formgroup', 'chiefformgroup'); |
92
|
|
|
|
93
|
|
|
// Custom validator for requiring on translations only the fallback locale |
94
|
|
|
// this is called in the validation as required-fallback-locale |
95
|
|
|
Validator::extendImplicit('requiredFallbackLocale', function ($attribute, $value, $parameters, $validator) { |
96
|
|
|
$fallbackLocale = config('app.fallback_locale'); |
97
|
|
|
|
98
|
|
|
if (false !== strpos($attribute, 'trans.' . $fallbackLocale . '.')) { |
99
|
|
|
return !!trim($value); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return true; |
103
|
|
|
}, 'Voor :attribute is minstens de default taal verplicht in te vullen, aub.'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function register() |
107
|
|
|
{ |
108
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/chief.php', 'thinktomorrow.chief'); |
109
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/chief-settings.php', 'thinktomorrow.chief-settings'); |
110
|
|
|
|
111
|
|
|
$this->setupEnvironmentProviders(); |
112
|
|
|
|
113
|
|
|
// Manager register is globally available |
114
|
|
|
$this->app->singleton(Register::class, function () { |
115
|
|
|
return new Register(); |
116
|
|
|
}); |
117
|
|
|
|
118
|
|
|
(new MacrosServiceProvider($this->app))->register(); |
119
|
|
|
(new AuthServiceProvider($this->app))->register(); |
120
|
|
|
(new EventServiceProvider($this->app))->register(); |
121
|
|
|
(new SquantoServiceProvider($this->app))->register(); |
122
|
|
|
(new SquantoManagerServiceProvider($this->app))->register(); |
123
|
|
|
(new SettingsServiceProvider($this->app))->register(); |
124
|
|
|
|
125
|
|
|
(new AssetLibraryServiceProvider($this->app))->register(); |
126
|
|
|
|
127
|
|
|
// Project defaults |
128
|
|
|
(new ChiefProjectServiceProvider($this->app))->register(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Conditionally loads providers for specific environments. |
133
|
|
|
* |
134
|
|
|
* The app()->register() will both trigger the register and boot |
135
|
|
|
* methods of the service provider |
136
|
|
|
*/ |
137
|
|
|
private function setupEnvironmentProviders() |
138
|
|
|
{ |
139
|
|
|
if (!$this->app->environment('production') && $services = config('app.providers-' . app()->environment(), false)) { |
140
|
|
|
foreach ($services as $service) { |
141
|
|
|
$this->app->register($service); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
private function registerChiefGuard() |
147
|
|
|
{ |
148
|
|
|
$this->app['config']["auth.guards.chief"] = [ |
149
|
|
|
'driver' => 'session', |
150
|
|
|
'provider' => 'chief', |
151
|
|
|
]; |
152
|
|
|
|
153
|
|
|
$this->app['config']["auth.providers.chief"] = [ |
154
|
|
|
'driver' => 'chief-eloquent', |
155
|
|
|
'model' => User::class, |
156
|
|
|
]; |
157
|
|
|
|
158
|
|
|
$this->app['config']["auth.passwords.chief"] = [ |
159
|
|
|
'provider' => 'chief', |
160
|
|
|
'table' => 'chief_password_resets', |
161
|
|
|
'expire' => 60, |
162
|
|
|
]; |
163
|
|
|
|
164
|
|
|
// Custom models for permission |
165
|
|
|
$this->app['config']['permission.models'] = [ |
166
|
|
|
'permission' => \Thinktomorrow\Chief\Authorization\Permission::class, |
167
|
|
|
'role' => \Thinktomorrow\Chief\Authorization\Role::class, |
168
|
|
|
]; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|