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