mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-04 16:20:26 +00:00
Refactored app service providers
Removed old pagination provider as url handling now achieved in a better way. Removed unused broadcast service provider. Moved view-based tweaks into specific provider. Reorganised provider config list.
This commit is contained in:
parent
67d7534d4f
commit
a6a78d2ab5
10 changed files with 65 additions and 150 deletions
|
@ -114,6 +114,8 @@ return [
|
||||||
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
|
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
|
||||||
Illuminate\Hashing\HashServiceProvider::class,
|
Illuminate\Hashing\HashServiceProvider::class,
|
||||||
Illuminate\Mail\MailServiceProvider::class,
|
Illuminate\Mail\MailServiceProvider::class,
|
||||||
|
Illuminate\Notifications\NotificationServiceProvider::class,
|
||||||
|
Illuminate\Pagination\PaginationServiceProvider::class,
|
||||||
Illuminate\Pipeline\PipelineServiceProvider::class,
|
Illuminate\Pipeline\PipelineServiceProvider::class,
|
||||||
Illuminate\Queue\QueueServiceProvider::class,
|
Illuminate\Queue\QueueServiceProvider::class,
|
||||||
Illuminate\Redis\RedisServiceProvider::class,
|
Illuminate\Redis\RedisServiceProvider::class,
|
||||||
|
@ -121,27 +123,22 @@ return [
|
||||||
Illuminate\Session\SessionServiceProvider::class,
|
Illuminate\Session\SessionServiceProvider::class,
|
||||||
Illuminate\Validation\ValidationServiceProvider::class,
|
Illuminate\Validation\ValidationServiceProvider::class,
|
||||||
Illuminate\View\ViewServiceProvider::class,
|
Illuminate\View\ViewServiceProvider::class,
|
||||||
Illuminate\Notifications\NotificationServiceProvider::class,
|
|
||||||
SocialiteProviders\Manager\ServiceProvider::class,
|
|
||||||
|
|
||||||
// Third party service providers
|
// Third party service providers
|
||||||
Intervention\Image\ImageServiceProvider::class,
|
|
||||||
Barryvdh\DomPDF\ServiceProvider::class,
|
Barryvdh\DomPDF\ServiceProvider::class,
|
||||||
Barryvdh\Snappy\ServiceProvider::class,
|
Barryvdh\Snappy\ServiceProvider::class,
|
||||||
|
Intervention\Image\ImageServiceProvider::class,
|
||||||
// BookStack replacement service providers (Extends Laravel)
|
SocialiteProviders\Manager\ServiceProvider::class,
|
||||||
BookStack\Providers\PaginationServiceProvider::class,
|
|
||||||
BookStack\Providers\TranslationServiceProvider::class,
|
|
||||||
|
|
||||||
// BookStack custom service providers
|
// BookStack custom service providers
|
||||||
BookStack\Providers\ThemeServiceProvider::class,
|
BookStack\Providers\ThemeServiceProvider::class,
|
||||||
BookStack\Providers\AuthServiceProvider::class,
|
|
||||||
BookStack\Providers\AppServiceProvider::class,
|
BookStack\Providers\AppServiceProvider::class,
|
||||||
BookStack\Providers\BroadcastServiceProvider::class,
|
BookStack\Providers\AuthServiceProvider::class,
|
||||||
BookStack\Providers\EventServiceProvider::class,
|
BookStack\Providers\EventServiceProvider::class,
|
||||||
BookStack\Providers\RouteServiceProvider::class,
|
BookStack\Providers\RouteServiceProvider::class,
|
||||||
BookStack\Providers\CustomFacadeProvider::class,
|
BookStack\Providers\TranslationServiceProvider::class,
|
||||||
BookStack\Providers\CustomValidationServiceProvider::class,
|
BookStack\Providers\ValidationRuleServiceProvider::class,
|
||||||
|
BookStack\Providers\ViewTweaksServiceProvider::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2,32 +2,44 @@
|
||||||
|
|
||||||
namespace BookStack\Providers;
|
namespace BookStack\Providers;
|
||||||
|
|
||||||
use BookStack\Auth\Access\LoginService;
|
use BookStack\Actions\ActivityLogger;
|
||||||
use BookStack\Auth\Access\SocialAuthService;
|
use BookStack\Auth\Access\SocialAuthService;
|
||||||
use BookStack\Entities\BreadcrumbsViewComposer;
|
|
||||||
use BookStack\Entities\Models\Book;
|
use BookStack\Entities\Models\Book;
|
||||||
use BookStack\Entities\Models\Bookshelf;
|
use BookStack\Entities\Models\Bookshelf;
|
||||||
use BookStack\Entities\Models\Chapter;
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use BookStack\Exceptions\WhoopsBookStackPrettyHandler;
|
use BookStack\Exceptions\WhoopsBookStackPrettyHandler;
|
||||||
use BookStack\Settings\Setting;
|
|
||||||
use BookStack\Settings\SettingService;
|
use BookStack\Settings\SettingService;
|
||||||
use BookStack\Util\CspService;
|
use BookStack\Util\CspService;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Illuminate\Contracts\Cache\Repository;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Pagination\Paginator;
|
|
||||||
use Illuminate\Support\Facades\Blade;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Support\Facades\View;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
|
|
||||||
use Psr\Http\Client\ClientInterface as HttpClientInterface;
|
use Psr\Http\Client\ClientInterface as HttpClientInterface;
|
||||||
use Whoops\Handler\HandlerInterface;
|
use Whoops\Handler\HandlerInterface;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Custom container bindings to register.
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
public $bindings = [
|
||||||
|
HandlerInterface::class => WhoopsBookStackPrettyHandler::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom singleton bindings to register.
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
public $singletons = [
|
||||||
|
'activity' => ActivityLogger::class,
|
||||||
|
SettingService::class => SettingService::class,
|
||||||
|
SocialAuthService::class => SocialAuthService::class,
|
||||||
|
CspService::class => CspService::class,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap any application services.
|
* Bootstrap any application services.
|
||||||
*
|
*
|
||||||
|
@ -43,11 +55,6 @@ class AppServiceProvider extends ServiceProvider
|
||||||
URL::forceScheme($isHttps ? 'https' : 'http');
|
URL::forceScheme($isHttps ? 'https' : 'http');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom blade view directives
|
|
||||||
Blade::directive('icon', function ($expression) {
|
|
||||||
return "<?php echo icon($expression); ?>";
|
|
||||||
});
|
|
||||||
|
|
||||||
// Allow longer string lengths after upgrade to utf8mb4
|
// Allow longer string lengths after upgrade to utf8mb4
|
||||||
Schema::defaultStringLength(191);
|
Schema::defaultStringLength(191);
|
||||||
|
|
||||||
|
@ -58,12 +65,6 @@ class AppServiceProvider extends ServiceProvider
|
||||||
'chapter' => Chapter::class,
|
'chapter' => Chapter::class,
|
||||||
'page' => Page::class,
|
'page' => Page::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// View Composers
|
|
||||||
View::composer('entities.breadcrumbs', BreadcrumbsViewComposer::class);
|
|
||||||
|
|
||||||
// Set paginator to use bootstrap-style pagination
|
|
||||||
Paginator::useBootstrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,22 +74,6 @@ class AppServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->bind(HandlerInterface::class, function ($app) {
|
|
||||||
return $app->make(WhoopsBookStackPrettyHandler::class);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->singleton(SettingService::class, function ($app) {
|
|
||||||
return new SettingService($app->make(Setting::class), $app->make(Repository::class));
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->singleton(SocialAuthService::class, function ($app) {
|
|
||||||
return new SocialAuthService($app->make(SocialiteFactory::class), $app->make(LoginService::class));
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->singleton(CspService::class, function ($app) {
|
|
||||||
return new CspService();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(HttpClientInterface::class, function ($app) {
|
$this->app->bind(HttpClientInterface::class, function ($app) {
|
||||||
return new Client([
|
return new Client([
|
||||||
'timeout' => 3,
|
'timeout' => 3,
|
||||||
|
|
|
@ -24,9 +24,7 @@ class AuthServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
// Password Configuration
|
// Password Configuration
|
||||||
// Changes here must be reflected in ApiDocsGenerate@getValidationAsString.
|
// Changes here must be reflected in ApiDocsGenerate@getValidationAsString.
|
||||||
Password::defaults(function () {
|
Password::defaults(fn () => Password::min(8));
|
||||||
return Password::min(8);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Custom guards
|
// Custom guards
|
||||||
Auth::extend('api-token', function ($app, $name, array $config) {
|
Auth::extend('api-token', function ($app, $name, array $config) {
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace BookStack\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class BroadcastServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Bootstrap any application services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
// Broadcast::routes();
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * Authenticate the user's personal channel...
|
|
||||||
// */
|
|
||||||
// Broadcast::channel('BookStack.User.*', function ($user, $userId) {
|
|
||||||
// return (int) $user->id === (int) $userId;
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace BookStack\Providers;
|
|
||||||
|
|
||||||
use BookStack\Actions\ActivityLogger;
|
|
||||||
use BookStack\Theming\ThemeService;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class CustomFacadeProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Bootstrap the application services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the application services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
$this->app->singleton('activity', function () {
|
|
||||||
return $this->app->make(ActivityLogger::class);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->singleton('theme', function () {
|
|
||||||
return $this->app->make(ThemeService::class);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,7 +10,7 @@ class EventServiceProvider extends ServiceProvider
|
||||||
/**
|
/**
|
||||||
* The event listener mappings for the application.
|
* The event listener mappings for the application.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<class-string, array<int, class-string>>
|
||||||
*/
|
*/
|
||||||
protected $listen = [
|
protected $listen = [
|
||||||
SocialiteWasCalled::class => [
|
SocialiteWasCalled::class => [
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace BookStack\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Pagination\PaginationServiceProvider as IlluminatePaginationServiceProvider;
|
|
||||||
use Illuminate\Pagination\Paginator;
|
|
||||||
|
|
||||||
class PaginationServiceProvider extends IlluminatePaginationServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Register the service provider.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
Paginator::viewFactoryResolver(function () {
|
|
||||||
return $this->app['view'];
|
|
||||||
});
|
|
||||||
|
|
||||||
Paginator::currentPathResolver(function () {
|
|
||||||
return url($this->app['request']->path());
|
|
||||||
});
|
|
||||||
|
|
||||||
Paginator::currentPageResolver(function ($pageName = 'page') {
|
|
||||||
$page = $this->app['request']->input($pageName);
|
|
||||||
|
|
||||||
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,9 +15,8 @@ class ThemeServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->singleton(ThemeService::class, function ($app) {
|
// Register the ThemeService as a singleton
|
||||||
return new ThemeService();
|
$this->app->singleton(ThemeService::class, fn ($app) => new ThemeService());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +26,7 @@ class ThemeServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
|
// Boot up the theme system
|
||||||
$themeService = $this->app->make(ThemeService::class);
|
$themeService = $this->app->make(ThemeService::class);
|
||||||
$themeService->readThemeActions();
|
$themeService->readThemeActions();
|
||||||
$themeService->dispatch(ThemeEvents::APP_BOOT, $this->app);
|
$themeService->dispatch(ThemeEvents::APP_BOOT, $this->app);
|
||||||
|
|
|
@ -6,7 +6,7 @@ use BookStack\Uploads\ImageService;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class CustomValidationServiceProvider extends ServiceProvider
|
class ValidationRuleServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Register our custom validation rules when the application boots.
|
* Register our custom validation rules when the application boots.
|
31
app/Providers/ViewTweaksServiceProvider.php
Normal file
31
app/Providers/ViewTweaksServiceProvider.php
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BookStack\Providers;
|
||||||
|
|
||||||
|
use BookStack\Entities\BreadcrumbsViewComposer;
|
||||||
|
use Illuminate\Pagination\Paginator;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class ViewTweaksServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// Set paginator to use bootstrap-style pagination
|
||||||
|
Paginator::useBootstrap();
|
||||||
|
|
||||||
|
// View Composers
|
||||||
|
View::composer('entities.breadcrumbs', BreadcrumbsViewComposer::class);
|
||||||
|
|
||||||
|
// Custom blade view directives
|
||||||
|
Blade::directive('icon', function ($expression) {
|
||||||
|
return "<?php echo icon($expression); ?>";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue