]> BookStack Code Mirror - bookstack/blob - app/Providers/AppServiceProvider.php
Merge pull request #1347 from cima/czech-translation
[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\Http\UploadedFile;
12 use Illuminate\Support\ServiceProvider;
13 use Schema;
14 use Validator;
15
16 class AppServiceProvider extends ServiceProvider
17 {
18     /**
19      * Bootstrap any application services.
20      *
21      * @return void
22      */
23     public function boot()
24     {
25         // Custom validation methods
26         Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
27             $validImageExtensions = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'tiff', 'webp'];
28             return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
29         });
30
31         Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
32             $uploadName = $value->getClientOriginalName();
33             return substr_count($uploadName, '.') < 2;
34         });
35
36
37         // Custom blade view directives
38         Blade::directive('icon', function ($expression) {
39             return "<?php echo icon($expression); ?>";
40         });
41
42         // Allow longer string lengths after upgrade to utf8mb4
43         Schema::defaultStringLength(191);
44
45         // Set morph-map due to namespace changes
46         Relation::morphMap([
47             'BookStack\\Bookshelf' => Bookshelf::class,
48             'BookStack\\Book' => Book::class,
49             'BookStack\\Chapter' => Chapter::class,
50             'BookStack\\Page' => Page::class,
51         ]);
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 }