]> BookStack Code Mirror - bookstack/blob - app/Providers/AppServiceProvider.php
Added force option for update-url command
[bookstack] / app / Providers / AppServiceProvider.php
1 <?php
2
3 namespace BookStack\Providers;
4
5 use BookStack\Actions\ActivityLogger;
6 use BookStack\Auth\Access\SocialAuthService;
7 use BookStack\Entities\Models\Book;
8 use BookStack\Entities\Models\Bookshelf;
9 use BookStack\Entities\Models\Chapter;
10 use BookStack\Entities\Models\Page;
11 use BookStack\Exceptions\BookStackExceptionHandlerPage;
12 use BookStack\Settings\SettingService;
13 use BookStack\Util\CspService;
14 use GuzzleHttp\Client;
15 use Illuminate\Contracts\Foundation\ExceptionRenderer;
16 use Illuminate\Database\Eloquent\Relations\Relation;
17 use Illuminate\Support\Facades\Schema;
18 use Illuminate\Support\Facades\URL;
19 use Illuminate\Support\ServiceProvider;
20 use Psr\Http\Client\ClientInterface as HttpClientInterface;
21
22 class AppServiceProvider extends ServiceProvider
23 {
24     /**
25      * Custom container bindings to register.
26      * @var string[]
27      */
28     public $bindings = [
29         ExceptionRenderer::class => BookStackExceptionHandlerPage::class,
30     ];
31
32     /**
33      * Custom singleton bindings to register.
34      * @var string[]
35      */
36     public $singletons = [
37         'activity' => ActivityLogger::class,
38         SettingService::class => SettingService::class,
39         SocialAuthService::class => SocialAuthService::class,
40         CspService::class => CspService::class,
41     ];
42
43     /**
44      * Bootstrap any application services.
45      *
46      * @return void
47      */
48     public function boot()
49     {
50         // Set root URL
51         $appUrl = config('app.url');
52         if ($appUrl) {
53             $isHttps = (strpos($appUrl, 'https://') === 0);
54             URL::forceRootUrl($appUrl);
55             URL::forceScheme($isHttps ? 'https' : 'http');
56         }
57
58         // Allow longer string lengths after upgrade to utf8mb4
59         Schema::defaultStringLength(191);
60
61         // Set morph-map for our relations to friendlier aliases
62         Relation::enforceMorphMap([
63             'bookshelf' => Bookshelf::class,
64             'book'      => Book::class,
65             'chapter'   => Chapter::class,
66             'page'      => Page::class,
67         ]);
68     }
69
70     /**
71      * Register any application services.
72      *
73      * @return void
74      */
75     public function register()
76     {
77         $this->app->bind(HttpClientInterface::class, function ($app) {
78             return new Client([
79                 'timeout' => 3,
80             ]);
81         });
82     }
83 }