2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Providers;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
2018-09-25 13:30:50 +02:00
|
|
|
use Blade;
|
2021-07-17 18:45:00 +02:00
|
|
|
use BookStack\Auth\Access\LoginService;
|
2021-03-19 17:16:26 +01:00
|
|
|
use BookStack\Auth\Access\SocialAuthService;
|
2021-06-26 17:23:15 +02:00
|
|
|
use BookStack\Entities\BreadcrumbsViewComposer;
|
2020-11-22 01:17:45 +01:00
|
|
|
use BookStack\Entities\Models\Book;
|
|
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
|
|
use BookStack\Entities\Models\Chapter;
|
|
|
|
use BookStack\Entities\Models\Page;
|
2018-09-25 13:30:50 +02:00
|
|
|
use BookStack\Settings\Setting;
|
2018-09-25 17:58:03 +02:00
|
|
|
use BookStack\Settings\SettingService;
|
2021-09-04 14:57:04 +02:00
|
|
|
use BookStack\Util\CspService;
|
2021-01-28 23:46:15 +01:00
|
|
|
use Illuminate\Contracts\Cache\Repository;
|
2018-09-25 13:30:50 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
2019-04-07 19:28:11 +02:00
|
|
|
use Illuminate\Support\Facades\View;
|
2015-07-12 21:01:42 +02:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2021-03-19 17:16:26 +01:00
|
|
|
use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
|
2018-09-25 13:30:50 +02:00
|
|
|
use Schema;
|
2019-08-04 15:26:39 +02:00
|
|
|
use URL;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2019-08-04 15:26:39 +02:00
|
|
|
// Set root URL
|
2019-09-01 13:07:51 +02:00
|
|
|
$appUrl = config('app.url');
|
|
|
|
if ($appUrl) {
|
|
|
|
$isHttps = (strpos($appUrl, 'https://') === 0);
|
|
|
|
URL::forceRootUrl($appUrl);
|
|
|
|
URL::forceScheme($isHttps ? 'https' : 'http');
|
|
|
|
}
|
2019-08-04 15:26:39 +02:00
|
|
|
|
2018-09-25 13:30:50 +02:00
|
|
|
// Custom blade view directives
|
|
|
|
Blade::directive('icon', function ($expression) {
|
2017-02-04 12:01:49 +01:00
|
|
|
return "<?php echo icon($expression); ?>";
|
|
|
|
});
|
2017-07-02 18:20:05 +02:00
|
|
|
|
|
|
|
// Allow longer string lengths after upgrade to utf8mb4
|
2018-09-25 13:30:50 +02:00
|
|
|
Schema::defaultStringLength(191);
|
|
|
|
|
|
|
|
// Set morph-map due to namespace changes
|
|
|
|
Relation::morphMap([
|
|
|
|
'BookStack\\Bookshelf' => Bookshelf::class,
|
2021-06-26 17:23:15 +02:00
|
|
|
'BookStack\\Book' => Book::class,
|
|
|
|
'BookStack\\Chapter' => Chapter::class,
|
|
|
|
'BookStack\\Page' => Page::class,
|
2018-09-25 13:30:50 +02:00
|
|
|
]);
|
2019-04-07 19:28:11 +02:00
|
|
|
|
|
|
|
// View Composers
|
2021-08-22 14:15:58 +02:00
|
|
|
View::composer('entities.breadcrumbs', BreadcrumbsViewComposer::class);
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2018-01-28 17:58:52 +01:00
|
|
|
$this->app->singleton(SettingService::class, function ($app) {
|
2021-01-28 23:46:15 +01:00
|
|
|
return new SettingService($app->make(Setting::class), $app->make(Repository::class));
|
2017-02-05 19:57:57 +01:00
|
|
|
});
|
2021-03-19 17:16:26 +01:00
|
|
|
|
2021-06-26 17:23:15 +02:00
|
|
|
$this->app->singleton(SocialAuthService::class, function ($app) {
|
2021-07-17 18:45:00 +02:00
|
|
|
return new SocialAuthService($app->make(SocialiteFactory::class), $app->make(LoginService::class));
|
2021-03-19 17:16:26 +01:00
|
|
|
});
|
2021-09-04 14:57:04 +02:00
|
|
|
|
2021-09-06 23:19:06 +02:00
|
|
|
$this->app->singleton(CspService::class, function ($app) {
|
2021-09-04 14:57:04 +02:00
|
|
|
return new CspService();
|
|
|
|
});
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|
|
|
|
}
|