1 <?php namespace BookStack\Providers;
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;
18 class AppServiceProvider extends ServiceProvider
21 * Bootstrap any application services.
25 public function boot()
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);
33 Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
34 $uploadName = $value->getClientOriginalName();
35 return substr_count($uploadName, '.') < 2;
38 // Custom blade view directives
39 Blade::directive('icon', function ($expression) {
40 return "<?php echo icon($expression); ?>";
43 // Allow longer string lengths after upgrade to utf8mb4
44 Schema::defaultStringLength(191);
46 // Set morph-map due to namespace changes
48 'BookStack\\Bookshelf' => Bookshelf::class,
49 'BookStack\\Book' => Book::class,
50 'BookStack\\Chapter' => Chapter::class,
51 'BookStack\\Page' => Page::class,
55 View::composer('partials.breadcrumbs', BreadcrumbsViewComposer::class);
59 * Register any application services.
63 public function register()
65 $this->app->singleton(SettingService::class, function ($app) {
66 return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));