3 namespace BookStack\App\Providers;
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;
22 class AppServiceProvider extends ServiceProvider
25 * Custom container bindings to register.
29 ExceptionRenderer::class => BookStackExceptionHandlerPage::class,
33 * Custom singleton bindings to register.
36 public $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,
45 * Bootstrap any application services.
49 public function boot()
52 $appUrl = config('app.url');
54 $isHttps = str_starts_with($appUrl, 'https://');
55 URL::forceRootUrl($appUrl);
56 URL::forceScheme($isHttps ? 'https' : 'http');
59 // Allow longer string lengths after upgrade to utf8mb4
60 Schema::defaultStringLength(191);
62 // Set morph-map for our relations to friendlier aliases
63 Relation::enforceMorphMap([
64 'bookshelf' => Bookshelf::class,
65 'book' => Book::class,
66 'chapter' => Chapter::class,
67 'page' => Page::class,
72 * Register any application services.
76 public function register()
78 $this->app->singleton(PermissionApplicator::class, function ($app) {
79 return new PermissionApplicator(null);