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