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