1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
6
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Livewire\LivewireServiceProvider; |
9
|
|
|
use Spatie\Sitemap\SitemapServiceProvider; |
10
|
|
|
use Thinktomorrow\AssetLibrary\AssetLibraryServiceProvider; |
11
|
|
|
use Thinktomorrow\Chief\Admin\Authorization\Console\GeneratePermissionCommand; |
12
|
|
|
use Thinktomorrow\Chief\Admin\Authorization\Console\GenerateRoleCommand; |
13
|
|
|
use Thinktomorrow\Chief\Admin\Nav\Nav; |
14
|
|
|
use Thinktomorrow\Chief\Admin\Settings\SettingFields; |
15
|
|
|
use Thinktomorrow\Chief\Admin\Settings\Settings; |
16
|
|
|
use Thinktomorrow\Chief\Admin\Settings\SettingsServiceProvider; |
17
|
|
|
use Thinktomorrow\Chief\Admin\Setup\CreateFragmentCommand; |
18
|
|
|
use Thinktomorrow\Chief\Admin\Setup\CreatePageCommand; |
19
|
|
|
use Thinktomorrow\Chief\Admin\Setup\CreatePageMigrationCommand; |
20
|
|
|
use Thinktomorrow\Chief\Admin\Setup\CreateViewCommand; |
21
|
|
|
use Thinktomorrow\Chief\Admin\Setup\FileManipulation; |
22
|
|
|
use Thinktomorrow\Chief\Admin\Setup\SetupConfig; |
23
|
|
|
use Thinktomorrow\Chief\Admin\Users\User; |
24
|
|
|
use Thinktomorrow\Chief\App\Console\CreateAdmin; |
25
|
|
|
use Thinktomorrow\Chief\App\Console\CreateDeveloper; |
26
|
|
|
use Thinktomorrow\Chief\App\Console\GenerateSitemap; |
27
|
|
|
use Thinktomorrow\Chief\App\Console\RefreshDatabase; |
28
|
|
|
use Thinktomorrow\Chief\App\Console\Seed; |
29
|
|
|
use Thinktomorrow\Chief\App\Http\Controllers\Back\System\SettingsController; |
30
|
|
|
use Thinktomorrow\Chief\Forms\FormsServiceProvider; |
31
|
|
|
use Thinktomorrow\Chief\Fragments\Database\FragmentModel; |
32
|
|
|
use Thinktomorrow\Chief\Managers\Register\Registry; |
33
|
|
|
use Thinktomorrow\Chief\Managers\Register\TaggedKeys; |
34
|
|
|
use Thinktomorrow\Squanto\SquantoManagerServiceProvider; |
35
|
|
|
use Thinktomorrow\Squanto\SquantoServiceProvider; |
36
|
|
|
|
37
|
|
|
class ChiefServiceProvider extends ServiceProvider |
38
|
|
|
{ |
39
|
|
|
public function boot(): void |
40
|
|
|
{ |
41
|
|
|
$this->registerChiefGuard(); |
42
|
|
|
$this->registerSquanto(); |
43
|
|
|
|
44
|
|
|
(new MacrosServiceProvider($this->app))->boot(); |
45
|
|
|
(new AuthServiceProvider($this->app))->boot(); |
46
|
|
|
(new EventServiceProvider($this->app))->boot(); |
47
|
|
|
(new ViewServiceProvider($this->app))->boot(); |
48
|
|
|
(new FormsServiceProvider($this->app))->boot(); |
49
|
|
|
(new SquantoServiceProvider($this->app))->boot(); |
50
|
|
|
(new SquantoManagerServiceProvider($this->app))->boot(); |
51
|
|
|
(new SettingsServiceProvider($this->app))->boot(); |
52
|
|
|
|
53
|
|
|
// Packages |
54
|
|
|
(new AssetLibraryServiceProvider($this->app))->boot(); |
55
|
|
|
(new SitemapServiceProvider($this->app))->boot(); |
56
|
|
|
(new LivewireServiceProvider($this->app))->boot(); |
57
|
|
|
|
58
|
|
|
// Project defaults |
59
|
|
|
(new ChiefRoutesServiceProvider($this->app))->boot(); |
60
|
|
|
|
61
|
|
|
// Addons |
62
|
|
|
foreach (config('chief.addons', []) as $addonServiceProvider) { |
63
|
|
|
(new $addonServiceProvider($this->app))->boot(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'chief'); |
67
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations'); |
68
|
|
|
$this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'chief'); |
69
|
|
|
|
70
|
|
|
$this->publishes([ |
71
|
|
|
__DIR__ . '/../../config/chief.php' => config_path('chief.php'), |
72
|
|
|
__DIR__ . '/../../config/chief-settings.php' => config_path('chief-settings.php'), |
73
|
|
|
], 'chief-config'); |
74
|
|
|
|
75
|
|
|
$this->publishes([ |
76
|
|
|
__DIR__ . '/../../public/chief-assets' => public_path('/chief-assets'), |
77
|
|
|
], 'chief-assets'); |
78
|
|
|
|
79
|
|
|
// Commands for both cli and web scripts |
80
|
|
|
$this->commands([ |
81
|
|
|
// Sitemap generation |
82
|
|
|
'command.chief:sitemap', |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
$this->app->bind('command.chief:sitemap', GenerateSitemap::class); |
86
|
|
|
|
87
|
|
|
// Commands for cli only |
88
|
|
|
if ($this->app->runningInConsole()) { |
89
|
|
|
$this->commands([ |
90
|
|
|
// Local development |
91
|
|
|
'command.chief:refresh', |
92
|
|
|
'command.chief:seed', |
93
|
|
|
|
94
|
|
|
// Project setup tools |
95
|
|
|
'command.chief:permission', |
96
|
|
|
'command.chief:role', |
97
|
|
|
|
98
|
|
|
'command.chief:admin', |
99
|
|
|
'command.chief:developer', |
100
|
|
|
'command.chief:page', |
101
|
|
|
'command.chief:page-migration', |
102
|
|
|
'command.chief:fragment', |
103
|
|
|
'command.chief:view', |
104
|
|
|
]); |
105
|
|
|
|
106
|
|
|
// Bind our commands to the container |
107
|
|
|
$this->app->bind('command.chief:refresh', RefreshDatabase::class); |
108
|
|
|
$this->app->bind('command.chief:seed', Seed::class); |
109
|
|
|
$this->app->bind('command.chief:permission', GeneratePermissionCommand::class); |
110
|
|
|
$this->app->bind('command.chief:role', GenerateRoleCommand::class); |
111
|
|
|
|
112
|
|
|
$this->app->bind('command.chief:page', CreatePageCommand::class); |
113
|
|
|
$this->app->bind('command.chief:page-migration', CreatePageMigrationCommand::class); |
114
|
|
|
$this->app->bind('command.chief:view', CreateViewCommand::class); |
115
|
|
|
$this->app->bind('command.chief:fragment', CreateFragmentCommand::class); |
116
|
|
|
$this->app->bind('command.chief:admin', CreateAdmin::class); |
117
|
|
|
$this->app->bind('command.chief:developer', CreateDeveloper::class); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
Relation::morphMap([ |
121
|
|
|
'fragmentmodel' => FragmentModel::class, |
122
|
|
|
]); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function register() |
126
|
|
|
{ |
127
|
|
|
if ($this->app->runningInConsole()) { |
128
|
|
|
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) { |
129
|
|
|
$schedule->command('chief:sitemap')->dailyAt("01:00"); |
130
|
|
|
}); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/chief.php', 'chief'); |
134
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/chief-settings.php', 'chief-settings'); |
135
|
|
|
|
136
|
|
|
$this->setupEnvironmentProviders(); |
137
|
|
|
|
138
|
|
|
$this->app->when(SettingsController::class) |
139
|
|
|
->needs(SettingFields::class) |
140
|
|
|
->give(function () { |
141
|
|
|
return new SettingFields(new Settings()); |
142
|
|
|
}); |
143
|
|
|
|
144
|
|
|
$this->app->singleton(Registry::class, function () { |
145
|
|
|
return new Registry([], [], new TaggedKeys()); |
146
|
|
|
}); |
147
|
|
|
|
148
|
|
|
// Global chief nav singleton |
149
|
|
|
$this->app->singleton(Nav::class, function () { |
150
|
|
|
return new Nav(); |
151
|
|
|
}); |
152
|
|
|
|
153
|
|
|
// Setup commands |
154
|
|
|
$this->app->bind(CreatePageCommand::class, function ($app) { |
155
|
|
|
return new CreatePageCommand($app->make(FileManipulation::class), new SetupConfig(config('chief.setup', []))); |
156
|
|
|
}); |
157
|
|
|
|
158
|
|
|
$this->app->bind(CreateFragmentCommand::class, function ($app) { |
159
|
|
|
return new CreateFragmentCommand($app->make(FileManipulation::class), new SetupConfig(config('chief.setup', []))); |
160
|
|
|
}); |
161
|
|
|
|
162
|
|
|
(new MacrosServiceProvider($this->app))->register(); |
163
|
|
|
(new AuthServiceProvider($this->app))->register(); |
164
|
|
|
(new EventServiceProvider($this->app))->register(); |
165
|
|
|
(new ViewServiceProvider($this->app))->register(); |
166
|
|
|
(new FormsServiceProvider($this->app))->register(); |
167
|
|
|
(new SquantoServiceProvider($this->app))->register(); |
168
|
|
|
(new SquantoManagerServiceProvider($this->app))->register(); |
169
|
|
|
(new SettingsServiceProvider($this->app))->register(); |
170
|
|
|
|
171
|
|
|
// Packages |
172
|
|
|
(new LivewireServiceProvider($this->app))->register(); |
173
|
|
|
(new AssetLibraryServiceProvider($this->app))->register(); |
174
|
|
|
(new SitemapServiceProvider($this->app))->register(); |
175
|
|
|
|
176
|
|
|
// Project defaults |
177
|
|
|
(new ChiefRoutesServiceProvider($this->app))->register(); |
178
|
|
|
|
179
|
|
|
// Addons |
180
|
|
|
foreach (config('chief.addons', []) as $addonServiceProvider) { |
181
|
|
|
(new $addonServiceProvider($this->app))->register(); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Conditionally loads providers for specific environments. |
187
|
|
|
* |
188
|
|
|
* The app()->register() will both trigger the register and boot |
189
|
|
|
* methods of the service provider |
190
|
|
|
* |
191
|
|
|
* @return void |
192
|
|
|
*/ |
193
|
|
|
private function setupEnvironmentProviders(): void |
194
|
|
|
{ |
195
|
|
|
if (! $this->app->environment('production') && $services = config('app.providers-' . app()->environment(), false)) { |
|
|
|
|
196
|
|
|
foreach ($services as $service) { |
197
|
|
|
$this->app->register($service); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
private function registerChiefGuard(): void |
203
|
|
|
{ |
204
|
|
|
$this->app['config']["auth.guards.chief"] = [ |
205
|
|
|
'driver' => 'session', |
206
|
|
|
'provider' => 'chief', |
207
|
|
|
]; |
208
|
|
|
|
209
|
|
|
$this->app['config']["auth.providers.chief"] = [ |
210
|
|
|
'driver' => 'chief-eloquent', |
211
|
|
|
'model' => User::class, |
212
|
|
|
]; |
213
|
|
|
|
214
|
|
|
$this->app['config']["auth.passwords.chief"] = [ |
215
|
|
|
'provider' => 'chief', |
216
|
|
|
'table' => 'chief_password_resets', |
217
|
|
|
'expire' => 60, |
218
|
|
|
]; |
219
|
|
|
|
220
|
|
|
// Custom models for permission |
221
|
|
|
$this->app['config']['permission.models'] = [ |
222
|
|
|
'permission' => \Thinktomorrow\Chief\Admin\Authorization\Permission::class, |
223
|
|
|
'role' => \Thinktomorrow\Chief\Admin\Authorization\Role::class, |
224
|
|
|
]; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
private function registerSquanto(): void |
228
|
|
|
{ |
229
|
|
|
// Project specific squanto files |
230
|
|
|
$this->app['view']->addNamespace('squanto', __DIR__ . '/../../resources/views/vendor/squanto'); |
231
|
|
|
|
232
|
|
|
// Chief squanto defaults |
233
|
|
|
$this->app['view']->addNamespace('squanto', base_path() . '/resources/views/vendor/thinktomorrow/chief/vendor/squanto'); |
234
|
|
|
|
235
|
|
|
// Use the chief routing |
236
|
|
|
$this->app['config']['squanto.use_default_routes'] = false; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|