3 namespace BookStack\Providers;
5 use BookStack\Auth\Access\LoginService;
6 use BookStack\Auth\Access\SocialAuthService;
7 use BookStack\Entities\BreadcrumbsViewComposer;
8 use BookStack\Entities\Models\Book;
9 use BookStack\Entities\Models\Bookshelf;
10 use BookStack\Entities\Models\Chapter;
11 use BookStack\Entities\Models\Page;
12 use BookStack\Exceptions\WhoopsBookStackPrettyHandler;
13 use BookStack\Settings\Setting;
14 use BookStack\Settings\SettingService;
15 use BookStack\Util\CspService;
16 use GuzzleHttp\Client;
17 use Illuminate\Contracts\Cache\Repository;
18 use Illuminate\Database\Eloquent\Relations\Relation;
19 use Illuminate\Pagination\Paginator;
20 use Illuminate\Support\Facades\Artisan;
21 use Illuminate\Support\Facades\Blade;
22 use Illuminate\Support\Facades\ParallelTesting;
23 use Illuminate\Support\Facades\Schema;
24 use Illuminate\Support\Facades\URL;
25 use Illuminate\Support\Facades\View;
26 use Illuminate\Support\ServiceProvider;
27 use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
28 use Psr\Http\Client\ClientInterface as HttpClientInterface;
29 use Whoops\Handler\HandlerInterface;
31 class AppServiceProvider extends ServiceProvider
34 * Bootstrap any application services.
38 public function boot()
41 $appUrl = config('app.url');
43 $isHttps = (strpos($appUrl, 'https://') === 0);
44 URL::forceRootUrl($appUrl);
45 URL::forceScheme($isHttps ? 'https' : 'http');
48 // Custom blade view directives
49 Blade::directive('icon', function ($expression) {
50 return "<?php echo icon($expression); ?>";
53 // Allow longer string lengths after upgrade to utf8mb4
54 Schema::defaultStringLength(191);
56 // Set morph-map for our relations to friendlier aliases
57 Relation::enforceMorphMap([
58 'bookshelf' => Bookshelf::class,
59 'book' => Book::class,
60 'chapter' => Chapter::class,
61 'page' => Page::class,
65 View::composer('entities.breadcrumbs', BreadcrumbsViewComposer::class);
67 // Set paginator to use bootstrap-style pagination
68 Paginator::useBootstrap();
70 // Setup database upon parallel testing database creation
71 ParallelTesting::setUpTestDatabase(function ($database, $token) {
72 Artisan::call('db:seed --class=DummyContentSeeder');
77 * Register any application services.
81 public function register()
83 $this->app->bind(HandlerInterface::class, function ($app) {
84 return $app->make(WhoopsBookStackPrettyHandler::class);
87 $this->app->singleton(SettingService::class, function ($app) {
88 return new SettingService($app->make(Setting::class), $app->make(Repository::class));
91 $this->app->singleton(SocialAuthService::class, function ($app) {
92 return new SocialAuthService($app->make(SocialiteFactory::class), $app->make(LoginService::class));
95 $this->app->singleton(CspService::class, function ($app) {
96 return new CspService();
99 $this->app->bind(HttpClientInterface::class, function ($app) {