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