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 BookStack\UrlGenerator;
12 use Illuminate\Database\Eloquent\Relations\Relation;
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 Blade::directive('exposeTranslations', function($expression) {
44 return "<?php \$__env->startPush('translations'); ?>" .
45 "<?php foreach({$expression} as \$key): ?>" .
46 '<meta name="translation" key="<?php echo e($key); ?>" value="<?php echo e(trans($key)); ?>">' . "\n" .
47 "<?php endforeach; ?>" .
48 '<?php $__env->stopPush(); ?>';
51 // Allow longer string lengths after upgrade to utf8mb4
52 Schema::defaultStringLength(191);
54 // Set morph-map due to namespace changes
56 'BookStack\\Bookshelf' => Bookshelf::class,
57 'BookStack\\Book' => Book::class,
58 'BookStack\\Chapter' => Chapter::class,
59 'BookStack\\Page' => Page::class,
63 View::composer('partials.breadcrumbs', BreadcrumbsViewComposer::class);
67 * Register any application services.
71 public function register()
73 $this->app->singleton(SettingService::class, function ($app) {
74 return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));
78 \Illuminate\Contracts\Routing\UrlGenerator::class,