3 namespace BookStack\Providers;
6 use BookStack\Auth\Access\LoginService;
7 use BookStack\Auth\Access\SocialAuthService;
8 use BookStack\Entities\BreadcrumbsViewComposer;
9 use BookStack\Entities\Models\Book;
10 use BookStack\Entities\Models\Bookshelf;
11 use BookStack\Entities\Models\Chapter;
12 use BookStack\Entities\Models\Page;
13 use BookStack\Settings\Setting;
14 use BookStack\Settings\SettingService;
15 use BookStack\Util\CspService;
16 use Illuminate\Contracts\Cache\Repository;
17 use Illuminate\Database\Eloquent\Relations\Relation;
18 use Illuminate\Support\Facades\View;
19 use Illuminate\Support\ServiceProvider;
20 use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
24 class AppServiceProvider extends ServiceProvider
27 * Bootstrap any application services.
31 public function boot()
34 $appUrl = config('app.url');
36 $isHttps = (strpos($appUrl, 'https://') === 0);
37 URL::forceRootUrl($appUrl);
38 URL::forceScheme($isHttps ? 'https' : 'http');
41 // Custom blade view directives
42 Blade::directive('icon', function ($expression) {
43 return "<?php echo icon($expression); ?>";
46 // Allow longer string lengths after upgrade to utf8mb4
47 Schema::defaultStringLength(191);
49 // Set morph-map due to namespace changes
51 'BookStack\\Bookshelf' => Bookshelf::class,
52 'BookStack\\Book' => Book::class,
53 'BookStack\\Chapter' => Chapter::class,
54 'BookStack\\Page' => Page::class,
58 View::composer('entities.breadcrumbs', BreadcrumbsViewComposer::class);
62 * Register any application services.
66 public function register()
68 $this->app->singleton(SettingService::class, function ($app) {
69 return new SettingService($app->make(Setting::class), $app->make(Repository::class));
72 $this->app->singleton(SocialAuthService::class, function ($app) {
73 return new SocialAuthService($app->make(SocialiteFactory::class), $app->make(LoginService::class));
76 $this->app->singleton(CspService::class, function ($app) {
77 return new CspService();