]> BookStack Code Mirror - bookstack/blob - app/Providers/AppServiceProvider.php
de_informal - remove comments from unused lines
[bookstack] / app / Providers / AppServiceProvider.php
1 <?php namespace BookStack\Providers;
2
3 use Blade;
4 use BookStack\Entities\Book;
5 use BookStack\Entities\Bookshelf;
6 use BookStack\Entities\Chapter;
7 use BookStack\Entities\Page;
8 use BookStack\Settings\Setting;
9 use BookStack\Settings\SettingService;
10 use Illuminate\Database\Eloquent\Relations\Relation;
11 use Illuminate\Support\ServiceProvider;
12 use Schema;
13 use Validator;
14
15 class AppServiceProvider extends ServiceProvider
16 {
17     /**
18      * Bootstrap any application services.
19      *
20      * @return void
21      */
22     public function boot()
23     {
24         // Custom validation methods
25         Validator::extend('is_image', function ($attribute, $value, $parameters, $validator) {
26             $imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/tiff', 'image/webp'];
27             return in_array($value->getMimeType(), $imageMimes);
28         });
29
30         // Custom blade view directives
31         Blade::directive('icon', function ($expression) {
32             return "<?php echo icon($expression); ?>";
33         });
34
35         // Allow longer string lengths after upgrade to utf8mb4
36         Schema::defaultStringLength(191);
37
38         // Set morph-map due to namespace changes
39         Relation::morphMap([
40             'BookStack\\Bookshelf' => Bookshelf::class,
41             'BookStack\\Book' => Book::class,
42             'BookStack\\Chapter' => Chapter::class,
43             'BookStack\\Page' => Page::class,
44         ]);
45     }
46
47     /**
48      * Register any application services.
49      *
50      * @return void
51      */
52     public function register()
53     {
54         $this->app->singleton(SettingService::class, function ($app) {
55             return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));
56         });
57     }
58 }