]> BookStack Code Mirror - bookstack/blob - app/Providers/AppServiceProvider.php
Added testing to cover debug view
[bookstack] / app / Providers / AppServiceProvider.php
1 <?php
2
3 namespace BookStack\Providers;
4
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 Illuminate\Contracts\Cache\Repository;
17 use Illuminate\Database\Eloquent\Relations\Relation;
18 use Illuminate\Support\Facades\Blade;
19 use Illuminate\Support\Facades\Schema;
20 use Illuminate\Support\Facades\URL;
21 use Illuminate\Support\Facades\View;
22 use Illuminate\Support\ServiceProvider;
23 use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
24 use Whoops\Handler\HandlerInterface;
25
26 class AppServiceProvider extends ServiceProvider
27 {
28     /**
29      * Bootstrap any application services.
30      *
31      * @return void
32      */
33     public function boot()
34     {
35         // Set root URL
36         $appUrl = config('app.url');
37         if ($appUrl) {
38             $isHttps = (strpos($appUrl, 'https://') === 0);
39             URL::forceRootUrl($appUrl);
40             URL::forceScheme($isHttps ? 'https' : 'http');
41         }
42
43         // Custom blade view directives
44         Blade::directive('icon', function ($expression) {
45             return "<?php echo icon($expression); ?>";
46         });
47
48         // Allow longer string lengths after upgrade to utf8mb4
49         Schema::defaultStringLength(191);
50
51         // Set morph-map due to namespace changes
52         Relation::morphMap([
53             'BookStack\\Bookshelf' => Bookshelf::class,
54             'BookStack\\Book'      => Book::class,
55             'BookStack\\Chapter'   => Chapter::class,
56             'BookStack\\Page'      => Page::class,
57         ]);
58
59         // View Composers
60         View::composer('entities.breadcrumbs', BreadcrumbsViewComposer::class);
61     }
62
63     /**
64      * Register any application services.
65      *
66      * @return void
67      */
68     public function register()
69     {
70         $this->app->bind(HandlerInterface::class, function($app) {
71             return $app->make(WhoopsBookStackPrettyHandler::class);
72         });
73
74         $this->app->singleton(SettingService::class, function ($app) {
75             return new SettingService($app->make(Setting::class), $app->make(Repository::class));
76         });
77
78         $this->app->singleton(SocialAuthService::class, function ($app) {
79             return new SocialAuthService($app->make(SocialiteFactory::class), $app->make(LoginService::class));
80         });
81
82         $this->app->singleton(CspService::class, function ($app) {
83             return new CspService();
84         });
85     }
86 }