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