]> BookStack Code Mirror - bookstack/blob - app/App/Providers/AppServiceProvider.php
Framework: Upgrade from Laravel 9 to 10
[bookstack] / app / App / Providers / AppServiceProvider.php
1 <?php
2
3 namespace BookStack\App\Providers;
4
5 use BookStack\Access\SocialDriverManager;
6 use BookStack\Activity\Tools\ActivityLogger;
7 use BookStack\Entities\Models\Book;
8 use BookStack\Entities\Models\Bookshelf;
9 use BookStack\Entities\Models\Chapter;
10 use BookStack\Entities\Models\Page;
11 use BookStack\Exceptions\BookStackExceptionHandlerPage;
12 use BookStack\Http\HttpRequestService;
13 use BookStack\Permissions\PermissionApplicator;
14 use BookStack\Settings\SettingService;
15 use BookStack\Util\CspService;
16 use Illuminate\Contracts\Foundation\ExceptionRenderer;
17 use Illuminate\Database\Eloquent\Relations\Relation;
18 use Illuminate\Support\Facades\Schema;
19 use Illuminate\Support\Facades\URL;
20 use Illuminate\Support\ServiceProvider;
21
22 class AppServiceProvider extends ServiceProvider
23 {
24     /**
25      * Custom container bindings to register.
26      * @var string[]
27      */
28     public array $bindings = [
29         ExceptionRenderer::class => BookStackExceptionHandlerPage::class,
30     ];
31
32     /**
33      * Custom singleton bindings to register.
34      * @var string[]
35      */
36     public array $singletons = [
37         'activity' => ActivityLogger::class,
38         SettingService::class => SettingService::class,
39         SocialDriverManager::class => SocialDriverManager::class,
40         CspService::class => CspService::class,
41         HttpRequestService::class => HttpRequestService::class,
42     ];
43
44     /**
45      * Register any application services.
46      */
47     public function register(): void
48     {
49         $this->app->singleton(PermissionApplicator::class, function ($app) {
50             return new PermissionApplicator(null);
51         });
52     }
53
54     /**
55      * Bootstrap any application services.
56      */
57     public function boot(): void
58     {
59         // Set root URL
60         $appUrl = config('app.url');
61         if ($appUrl) {
62             $isHttps = str_starts_with($appUrl, 'https://');
63             URL::forceRootUrl($appUrl);
64             URL::forceScheme($isHttps ? 'https' : 'http');
65         }
66
67         // Allow longer string lengths after upgrade to utf8mb4
68         Schema::defaultStringLength(191);
69
70         // Set morph-map for our relations to friendlier aliases
71         Relation::enforceMorphMap([
72             'bookshelf' => Bookshelf::class,
73             'book'      => Book::class,
74             'chapter'   => Chapter::class,
75             'page'      => Page::class,
76         ]);
77     }
78 }