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\Support\Facades\View;
13 use Illuminate\Support\ServiceProvider;
18 class AppServiceProvider extends ServiceProvider
21 * Bootstrap any application services.
25 public function boot()
28 URL::forceRootUrl(config('app.url'));
30 // Custom validation methods
31 Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
32 $validImageExtensions = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'tiff', 'webp'];
33 return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
36 Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
37 $uploadName = $value->getClientOriginalName();
38 return substr_count($uploadName, '.') < 2;
41 // Custom blade view directives
42 Blade::directive('icon', function ($expression) {
43 return "<?php echo icon($expression); ?>";
46 Blade::directive('exposeTranslations', function($expression) {
47 return "<?php \$__env->startPush('translations'); ?>" .
48 "<?php foreach({$expression} as \$key): ?>" .
49 '<meta name="translation" key="<?php echo e($key); ?>" value="<?php echo e(trans($key)); ?>">' . "\n" .
50 "<?php endforeach; ?>" .
51 '<?php $__env->stopPush(); ?>';
54 // Allow longer string lengths after upgrade to utf8mb4
55 Schema::defaultStringLength(191);
57 // Set morph-map due to namespace changes
59 'BookStack\\Bookshelf' => Bookshelf::class,
60 'BookStack\\Book' => Book::class,
61 'BookStack\\Chapter' => Chapter::class,
62 'BookStack\\Page' => Page::class,
66 View::composer('partials.breadcrumbs', BreadcrumbsViewComposer::class);
70 * Register any application services.
74 public function register()
76 $this->app->singleton(SettingService::class, function ($app) {
77 return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));