]> BookStack Code Mirror - bookstack/blob - app/Providers/AppServiceProvider.php
fix missing word
[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\BreadcrumbsViewComposer;
7 use BookStack\Entities\Chapter;
8 use BookStack\Entities\Page;
9 use BookStack\Settings\Setting;
10 use BookStack\Settings\SettingService;
11 use Illuminate\Database\Eloquent\Relations\Relation;
12 use Illuminate\Http\UploadedFile;
13 use Illuminate\Support\Facades\View;
14 use Illuminate\Support\ServiceProvider;
15 use Schema;
16 use Validator;
17
18 class AppServiceProvider extends ServiceProvider
19 {
20     /**
21      * Bootstrap any application services.
22      *
23      * @return void
24      */
25     public function boot()
26     {
27         // Custom validation methods
28         Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
29             $validImageExtensions = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'tiff', 'webp'];
30             return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
31         });
32
33         Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
34             $uploadName = $value->getClientOriginalName();
35             return substr_count($uploadName, '.') < 2;
36         });
37
38         // Custom blade view directives
39         Blade::directive('icon', function ($expression) {
40             return "<?php echo icon($expression); ?>";
41         });
42
43         // Allow longer string lengths after upgrade to utf8mb4
44         Schema::defaultStringLength(191);
45
46         // Set morph-map due to namespace changes
47         Relation::morphMap([
48             'BookStack\\Bookshelf' => Bookshelf::class,
49             'BookStack\\Book' => Book::class,
50             'BookStack\\Chapter' => Chapter::class,
51             'BookStack\\Page' => Page::class,
52         ]);
53
54         // View Composers
55         View::composer('partials.breadcrumbs', BreadcrumbsViewComposer::class);
56     }
57
58     /**
59      * Register any application services.
60      *
61      * @return void
62      */
63     public function register()
64     {
65         $this->app->singleton(SettingService::class, function ($app) {
66             return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));
67         });
68     }
69 }