|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Auth\Events\Login; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation; |
|
7
|
|
|
use Illuminate\Support\Facades\Auth; |
|
8
|
|
|
use Illuminate\Support\Facades\Blade; |
|
9
|
|
|
use Illuminate\Support\Facades\Event; |
|
10
|
|
|
use Illuminate\Support\ServiceProvider; |
|
11
|
|
|
use Spatie\Sitemap\SitemapServiceProvider; |
|
12
|
|
|
use Thinktomorrow\Chief\Admin\Authorization\ChiefUserProvider; |
|
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\Users\Application\EnableUser; |
|
17
|
|
|
use Thinktomorrow\Chief\Admin\Users\Invites\Application\SendInvite; |
|
18
|
|
|
use Thinktomorrow\Chief\Admin\Users\Invites\Events\InviteAccepted; |
|
19
|
|
|
use Thinktomorrow\Chief\Admin\Users\Invites\Events\UserInvited; |
|
20
|
|
|
use Thinktomorrow\Chief\Admin\Users\User; |
|
21
|
|
|
use Thinktomorrow\Chief\App\Console\GenerateImageSitemap; |
|
22
|
|
|
use Thinktomorrow\Chief\App\Console\GenerateSitemap; |
|
23
|
|
|
use Thinktomorrow\Chief\App\Http\Controllers\Back\System\SettingsController; |
|
24
|
|
|
use Thinktomorrow\Chief\App\Listeners\LogSuccessfulLogin; |
|
25
|
|
|
use Thinktomorrow\Chief\Assets\AssetsServiceProvider; |
|
26
|
|
|
use Thinktomorrow\Chief\Forms\Events\FormUpdated; |
|
27
|
|
|
use Thinktomorrow\Chief\Forms\FormsServiceProvider; |
|
28
|
|
|
use Thinktomorrow\Chief\Fragments\Actions\DeleteFragment; |
|
29
|
|
|
use Thinktomorrow\Chief\Fragments\Actions\UpdateFragmentMetadata; |
|
30
|
|
|
use Thinktomorrow\Chief\Fragments\Database\FragmentModel; |
|
31
|
|
|
use Thinktomorrow\Chief\Fragments\Events\FragmentAdded; |
|
32
|
|
|
use Thinktomorrow\Chief\Fragments\Events\FragmentDetached; |
|
33
|
|
|
use Thinktomorrow\Chief\Fragments\Events\FragmentDuplicated; |
|
34
|
|
|
use Thinktomorrow\Chief\Fragments\Events\FragmentsReordered; |
|
35
|
|
|
use Thinktomorrow\Chief\Fragments\Events\FragmentUpdated; |
|
36
|
|
|
use Thinktomorrow\Chief\Fragments\FragmentsServiceProvider; |
|
37
|
|
|
use Thinktomorrow\Chief\ManagedModels\Actions\DeleteModel; |
|
38
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelArchived; |
|
39
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelCreated; |
|
40
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelDeleted; |
|
41
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelPublished; |
|
42
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelQueuedForDeletion; |
|
43
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelUnPublished; |
|
44
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelUpdated; |
|
45
|
|
|
use Thinktomorrow\Chief\ManagedModels\Events\ManagedModelUrlUpdated; |
|
46
|
|
|
use Thinktomorrow\Chief\ManagedModels\Listeners\PropagateArchivedUrl; |
|
47
|
|
|
use Thinktomorrow\Chief\ManagedModels\Listeners\TriggerPageChangedEvent; |
|
48
|
|
|
use Thinktomorrow\Chief\Managers\Register\Registry; |
|
49
|
|
|
use Thinktomorrow\Chief\Shared\AdminEnvironment; |
|
50
|
|
|
use Thinktomorrow\Chief\Shared\Concerns\Nestable\Actions\PropagateUrlChange; |
|
|
|
|
|
|
51
|
|
|
use Thinktomorrow\Chief\Site\Menu\Application\ProjectModelData; |
|
52
|
|
|
use Thinktomorrow\Chief\Site\Menu\Events\MenuItemCreated; |
|
53
|
|
|
use Thinktomorrow\Chief\Site\Menu\Events\MenuItemUpdated; |
|
54
|
|
|
use Thinktomorrow\Chief\Site\Menu\MenuItem; |
|
55
|
|
|
use Thinktomorrow\Chief\Site\Urls\Application\CreateUrlForPage; |
|
56
|
|
|
use Thinktomorrow\Squanto\SquantoManagerServiceProvider; |
|
57
|
|
|
use Thinktomorrow\Squanto\SquantoServiceProvider; |
|
58
|
|
|
|
|
59
|
|
|
class ChiefServiceProvider extends ServiceProvider |
|
60
|
|
|
{ |
|
61
|
|
|
private SitemapServiceProvider $sitemapServiceProvider; |
|
62
|
|
|
|
|
63
|
|
|
public function __construct($app) |
|
64
|
|
|
{ |
|
65
|
|
|
parent::__construct($app); |
|
66
|
|
|
|
|
67
|
|
|
// Spatie Package logic sets a Package property on register so this needs to be retained when calling boot as well |
|
68
|
|
|
$this->sitemapServiceProvider = new SitemapServiceProvider($app); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function boot(): void |
|
72
|
|
|
{ |
|
73
|
|
|
/* |
|
74
|
|
|
* ------------------------------------ |
|
75
|
|
|
* Boot required for frontend |
|
76
|
|
|
* ------------------------------------ |
|
77
|
|
|
*/ |
|
78
|
|
|
$this->bootFrontendEssentials(); |
|
79
|
|
|
|
|
80
|
|
|
if (! $this->app->make(AdminEnvironment::class)->check(request())) { |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/* |
|
85
|
|
|
* ------------------------------------ |
|
86
|
|
|
* Boot required for admin |
|
87
|
|
|
* ------------------------------------ |
|
88
|
|
|
*/ |
|
89
|
|
|
$this->bootChiefSquanto(); |
|
90
|
|
|
$this->bootEvents(); |
|
91
|
|
|
|
|
92
|
|
|
(new ViewServiceProvider($this->app))->boot(); |
|
93
|
|
|
(new FormsServiceProvider($this->app))->boot(); |
|
94
|
|
|
(new FragmentsServiceProvider($this->app))->boot(); |
|
95
|
|
|
(new \Thinktomorrow\Chief\Table\TableServiceProvider($this->app))->boot(); |
|
96
|
|
|
(new AssetsServiceProvider($this->app))->boot(); |
|
97
|
|
|
(new SquantoManagerServiceProvider($this->app))->boot(); |
|
98
|
|
|
$this->sitemapServiceProvider->boot(); |
|
99
|
|
|
|
|
100
|
|
|
// Sitemap command is used by both cli and web scripts |
|
101
|
|
|
$this->commands(['command.chief:sitemap']); |
|
102
|
|
|
$this->commands(['command.chief:image-sitemap']); |
|
103
|
|
|
$this->app->bind('command.chief:sitemap', GenerateSitemap::class); |
|
104
|
|
|
$this->app->bind('command.chief:image-sitemap', GenerateImageSitemap::class); |
|
105
|
|
|
|
|
106
|
|
|
if ($this->app->runningInConsole()) { |
|
107
|
|
|
(new ConsoleServiceProvider($this->app))->boot(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function register() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/chief.php', 'chief'); |
|
114
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/chief-settings.php', 'chief-settings'); |
|
115
|
|
|
|
|
116
|
|
|
if ($this->app->runningInConsole()) { |
|
117
|
|
|
(new ConsoleServiceProvider($this->app))->register(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$this->app->singleton(Registry::class, function () { |
|
121
|
|
|
return new Registry([]); |
|
122
|
|
|
}); |
|
123
|
|
|
|
|
124
|
|
|
$this->app->singleton(Settings::class, function () { |
|
125
|
|
|
return new Settings(); |
|
126
|
|
|
}); |
|
127
|
|
|
|
|
128
|
|
|
(new SquantoServiceProvider($this->app))->register(); |
|
129
|
|
|
|
|
130
|
|
|
if ($this->app->make(AdminEnvironment::class)->check(request())) { |
|
131
|
|
|
$this->app->when(SettingsController::class) |
|
132
|
|
|
->needs(SettingFields::class) |
|
133
|
|
|
->give(function () { |
|
134
|
|
|
return new SettingFields(new Settings()); |
|
135
|
|
|
}); |
|
136
|
|
|
|
|
137
|
|
|
// Global chief nav singleton |
|
138
|
|
|
$this->app->singleton(Nav::class, function () { |
|
139
|
|
|
return new Nav(); |
|
140
|
|
|
}); |
|
141
|
|
|
|
|
142
|
|
|
(new AssetsServiceProvider($this->app))->register(); |
|
143
|
|
|
(new SquantoManagerServiceProvider($this->app))->register(); |
|
144
|
|
|
$this->sitemapServiceProvider->register(); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
private function bootChiefAuth(): void |
|
149
|
|
|
{ |
|
150
|
|
|
$this->app['config']['auth.guards.chief'] = [ |
|
151
|
|
|
'driver' => 'session', |
|
152
|
|
|
'provider' => 'chief', |
|
153
|
|
|
]; |
|
154
|
|
|
|
|
155
|
|
|
$this->app['config']['auth.providers.chief'] = [ |
|
156
|
|
|
'driver' => 'chief-eloquent', |
|
157
|
|
|
'model' => User::class, |
|
158
|
|
|
]; |
|
159
|
|
|
|
|
160
|
|
|
$this->app['config']['auth.passwords.chief'] = [ |
|
161
|
|
|
'provider' => 'chief', |
|
162
|
|
|
'table' => 'chief_password_resets', |
|
163
|
|
|
'expire' => 60, |
|
164
|
|
|
]; |
|
165
|
|
|
|
|
166
|
|
|
// Custom models for permission |
|
167
|
|
|
$this->app['config']['permission.models'] = [ |
|
168
|
|
|
'permission' => \Thinktomorrow\Chief\Admin\Authorization\Permission::class, |
|
169
|
|
|
'role' => \Thinktomorrow\Chief\Admin\Authorization\Role::class, |
|
170
|
|
|
]; |
|
171
|
|
|
|
|
172
|
|
|
Auth::provider('chief-eloquent', function ($app, array $config) { |
|
173
|
|
|
return new ChiefUserProvider($app['hash'], $config['model']); |
|
174
|
|
|
}); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
private function bootChiefSquanto(): void |
|
178
|
|
|
{ |
|
179
|
|
|
// Project specific squanto files |
|
180
|
|
|
$this->app['view']->addNamespace('squanto', __DIR__ . '/../../resources/views/vendor/squanto'); |
|
181
|
|
|
|
|
182
|
|
|
// Chief squanto defaults |
|
183
|
|
|
$this->app['view']->addNamespace('squanto', base_path() . '/resources/views/vendor/thinktomorrow/chief/vendor/squanto'); |
|
184
|
|
|
|
|
185
|
|
|
// Use the chief routing |
|
186
|
|
|
$this->app['config']['squanto.use_default_routes'] = false; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
private function bootEvents(): void |
|
190
|
|
|
{ |
|
191
|
|
|
// User events |
|
192
|
|
|
Event::listen(Login::class, LogSuccessfulLogin::class); |
|
193
|
|
|
Event::listen(UserInvited::class, SendInvite::class); |
|
194
|
|
|
Event::listen(InviteAccepted::class, EnableUser::class . '@onAcceptingInvite'); |
|
195
|
|
|
|
|
196
|
|
|
// Managed model events |
|
197
|
|
|
Event::listen(ManagedModelCreated::class, [CreateUrlForPage::class, 'onManagedModelCreated']); |
|
198
|
|
|
Event::listen(ManagedModelUrlUpdated::class, [TriggerPageChangedEvent::class, 'onManagedModelUrlUpdated']); |
|
199
|
|
|
Event::listen(ManagedModelUrlUpdated::class, [ProjectModelData::class, 'onManagedModelUrlUpdated']); |
|
200
|
|
|
Event::listen(ManagedModelUrlUpdated::class, [PropagateUrlChange::class, 'onManagedModelUrlUpdated']); |
|
201
|
|
|
Event::listen(ManagedModelUpdated::class, [TriggerPageChangedEvent::class, 'onManagedModelUpdated']); |
|
202
|
|
|
Event::listen(ManagedModelUpdated::class, [ProjectModelData::class, 'onManagedModelUpdated']); |
|
203
|
|
|
Event::listen(ManagedModelArchived::class, [PropagateArchivedUrl::class, 'onManagedModelArchived']); |
|
204
|
|
|
Event::listen(ManagedModelArchived::class, [ProjectModelData::class, 'onManagedModelArchived']); |
|
205
|
|
|
Event::listen(ManagedModelPublished::class, [ProjectModelData::class, 'onManagedModelPublished']); |
|
206
|
|
|
Event::listen(ManagedModelUnPublished::class, [ProjectModelData::class, 'onManagedModelUnPublished']); |
|
207
|
|
|
Event::listen(ManagedModelQueuedForDeletion::class, [DeleteModel::class, 'onManagedModelQueuedForDeletion']); |
|
208
|
|
|
Event::listen(ManagedModelDeleted::class, [TriggerPageChangedEvent::class, 'onManagedModelDeleted']); |
|
209
|
|
|
Event::listen(ManagedModelDeleted::class, [ProjectModelData::class, 'onManagedModelDeleted']); |
|
210
|
|
|
|
|
211
|
|
|
// Fragment events |
|
212
|
|
|
Event::listen(FragmentDetached::class, [TriggerPageChangedEvent::class, 'onFragmentDetached']); |
|
213
|
|
|
Event::listen(FragmentDetached::class, [DeleteFragment::class, 'onFragmentDetached']); |
|
214
|
|
|
Event::listen(FragmentDetached::class, [UpdateFragmentMetadata::class, 'onFragmentDetached']); |
|
215
|
|
|
Event::listen(FragmentAdded::class, [TriggerPageChangedEvent::class, 'onFragmentAdded']); |
|
216
|
|
|
Event::listen(FragmentAdded::class, [UpdateFragmentMetadata::class, 'onFragmentAdded']); |
|
217
|
|
|
Event::listen(FragmentUpdated::class, [TriggerPageChangedEvent::class, 'onFragmentUpdated']); |
|
218
|
|
|
Event::listen(FragmentDuplicated::class, [TriggerPageChangedEvent::class, 'onFragmentDuplicated']); |
|
219
|
|
|
Event::listen(FragmentDuplicated::class, [UpdateFragmentMetadata::class, 'onFragmentDuplicated']); |
|
220
|
|
|
Event::listen(FragmentsReordered::class, [TriggerPageChangedEvent::class, 'onFragmentsReordered']); |
|
221
|
|
|
|
|
222
|
|
|
// Form events |
|
223
|
|
|
Event::listen(FormUpdated::class, [TriggerPageChangedEvent::class, 'onFormUpdated']); |
|
224
|
|
|
Event::listen(FormUpdated::class, [ProjectModelData::class, 'onFormUpdated']); |
|
225
|
|
|
|
|
226
|
|
|
// Menu events |
|
227
|
|
|
Event::listen(MenuItemCreated::class, [ProjectModelData::class, 'onMenuItemCreated']); |
|
228
|
|
|
Event::listen(MenuItemUpdated::class, [ProjectModelData::class, 'onMenuItemUpdated']); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
private function bootFrontendEssentials() |
|
232
|
|
|
{ |
|
233
|
|
|
(new SquantoServiceProvider($this->app))->boot(); |
|
234
|
|
|
(new RoutesServiceProvider($this->app))->boot(); |
|
235
|
|
|
|
|
236
|
|
|
$this->bootChiefAuth(); |
|
237
|
|
|
|
|
238
|
|
|
Relation::morphMap(['fragmentmodel' => FragmentModel::class]); |
|
239
|
|
|
Relation::morphMap(['chiefuser' => User::class]); |
|
240
|
|
|
Relation::morphMap(['menuitem' => MenuItem::class]); |
|
241
|
|
|
|
|
242
|
|
|
Blade::directive('fragments', function () { |
|
243
|
|
|
return '<?php echo app(\\Thinktomorrow\\Chief\\Fragments\\FragmentsRenderer::class)->render($model instanceof \Thinktomorrow\Chief\Shared\Concerns\Nestable\Tree\NestedNode ? $model->getModel() : $model, get_defined_vars()); ?>'; |
|
244
|
|
|
}); |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths