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