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 $appUrl = config('app.url');
30 $isHttps = (strpos($appUrl, 'https://') === 0);
31 URL::forceRootUrl($appUrl);
32 URL::forceScheme($isHttps ? 'https' : 'http');
35 // Custom validation methods
36 Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
37 $validImageExtensions = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'tiff', 'webp'];
38 return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
41 Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
42 $uploadName = $value->getClientOriginalName();
43 return substr_count($uploadName, '.') < 2;
46 // Custom blade view directives
47 Blade::directive('icon', function ($expression) {
48 return "<?php echo icon($expression); ?>";
51 Blade::directive('exposeTranslations', function($expression) {
52 return "<?php \$__env->startPush('translations'); ?>" .
53 "<?php foreach({$expression} as \$key): ?>" .
54 '<meta name="translation" key="<?php echo e($key); ?>" value="<?php echo e(trans($key)); ?>">' . "\n" .
55 "<?php endforeach; ?>" .
56 '<?php $__env->stopPush(); ?>';
59 // Allow longer string lengths after upgrade to utf8mb4
60 Schema::defaultStringLength(191);
62 // Set morph-map due to namespace changes
64 'BookStack\\Bookshelf' => Bookshelf::class,
65 'BookStack\\Book' => Book::class,
66 'BookStack\\Chapter' => Chapter::class,
67 'BookStack\\Page' => Page::class,
71 View::composer('partials.breadcrumbs', BreadcrumbsViewComposer::class);
75 * Register any application services.
79 public function register()
81 $this->app->singleton(SettingService::class, function ($app) {
82 return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));