2016-09-03 11:08:58 +00:00
|
|
|
<?php namespace BookStack\Providers;
|
2015-07-12 19:01:42 +00:00
|
|
|
|
2018-09-25 11:30:50 +00:00
|
|
|
use Blade;
|
|
|
|
use BookStack\Entities\Book;
|
|
|
|
use BookStack\Entities\Bookshelf;
|
|
|
|
use BookStack\Entities\Chapter;
|
|
|
|
use BookStack\Entities\Page;
|
|
|
|
use BookStack\Settings\Setting;
|
2018-09-25 15:58:03 +00:00
|
|
|
use BookStack\Settings\SettingService;
|
2018-09-25 11:30:50 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
2015-07-12 19:01:42 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2018-09-25 11:30:50 +00:00
|
|
|
use Schema;
|
2016-12-31 14:38:04 +00:00
|
|
|
use Validator;
|
2015-07-12 19:01:42 +00:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2016-07-01 19:11:49 +00:00
|
|
|
// Custom validation methods
|
2018-03-24 15:25:13 +00:00
|
|
|
Validator::extend('is_image', function ($attribute, $value, $parameters, $validator) {
|
2016-07-01 19:11:49 +00:00
|
|
|
$imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/tiff', 'image/webp'];
|
|
|
|
return in_array($value->getMimeType(), $imageMimes);
|
|
|
|
});
|
2017-02-04 11:01:49 +00:00
|
|
|
|
2018-09-25 11:30:50 +00:00
|
|
|
// Custom blade view directives
|
|
|
|
Blade::directive('icon', function ($expression) {
|
2017-02-04 11:01:49 +00:00
|
|
|
return "<?php echo icon($expression); ?>";
|
|
|
|
});
|
2017-07-02 16:20:05 +00:00
|
|
|
|
|
|
|
// Allow longer string lengths after upgrade to utf8mb4
|
2018-09-25 11:30:50 +00:00
|
|
|
Schema::defaultStringLength(191);
|
|
|
|
|
|
|
|
// Set morph-map due to namespace changes
|
|
|
|
Relation::morphMap([
|
|
|
|
'BookStack\\Bookshelf' => Bookshelf::class,
|
|
|
|
'BookStack\\Book' => Book::class,
|
|
|
|
'BookStack\\Chapter' => Chapter::class,
|
|
|
|
'BookStack\\Page' => Page::class,
|
|
|
|
]);
|
2015-07-12 19:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2018-01-28 16:58:52 +00:00
|
|
|
$this->app->singleton(SettingService::class, function ($app) {
|
2017-02-05 18:57:57 +00:00
|
|
|
return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository'));
|
|
|
|
});
|
2015-07-12 19:01:42 +00:00
|
|
|
}
|
|
|
|
}
|