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