From 3e0cd3a21ffa0c92ba9784ab018c29306eed5426 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 14 Dec 2018 01:47:54 +0100 Subject: [PATCH] Use class constant to get qualified class names --- src/Database/DatabaseServiceProvider.php | 13 +++++---- src/Database/MigrationServiceProvider.php | 5 ++-- src/Post/PostServiceProvider.php | 6 ++-- src/Search/SearchServiceProvider.php | 34 +++++++++++++++-------- src/Settings/SettingsServiceProvider.php | 3 +- src/User/UserServiceProvider.php | 9 ++++-- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/Database/DatabaseServiceProvider.php b/src/Database/DatabaseServiceProvider.php index 44c7acfd1..12892f2fb 100644 --- a/src/Database/DatabaseServiceProvider.php +++ b/src/Database/DatabaseServiceProvider.php @@ -12,7 +12,10 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionResolver; +use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\Connectors\ConnectionFactory; class DatabaseServiceProvider extends AbstractServiceProvider @@ -28,14 +31,14 @@ class DatabaseServiceProvider extends AbstractServiceProvider $dbConfig = $this->app->config('database'); $dbConfig['engine'] = 'InnoDB'; $connection = $factory->make($dbConfig); - $connection->setEventDispatcher($this->app->make('Illuminate\Contracts\Events\Dispatcher')); + $connection->setEventDispatcher($this->app->make(Dispatcher::class)); return $connection; }); - $this->app->alias('flarum.db', 'Illuminate\Database\ConnectionInterface'); + $this->app->alias('flarum.db', ConnectionInterface::class); - $this->app->singleton('Illuminate\Database\ConnectionResolverInterface', function () { + $this->app->singleton(ConnectionResolverInterface::class, function () { $resolver = new ConnectionResolver([ 'flarum' => $this->app->make('flarum.db'), ]); @@ -44,7 +47,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider return $resolver; }); - $this->app->alias('Illuminate\Database\ConnectionResolverInterface', 'db'); + $this->app->alias(ConnectionResolverInterface::class, 'db'); } /** @@ -52,7 +55,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider */ public function boot() { - AbstractModel::setConnectionResolver($this->app->make('Illuminate\Database\ConnectionResolverInterface')); + AbstractModel::setConnectionResolver($this->app->make(ConnectionResolverInterface::class)); AbstractModel::setEventDispatcher($this->app->make('events')); } } diff --git a/src/Database/MigrationServiceProvider.php b/src/Database/MigrationServiceProvider.php index 165cec0da..9ffc6af7a 100644 --- a/src/Database/MigrationServiceProvider.php +++ b/src/Database/MigrationServiceProvider.php @@ -13,6 +13,7 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Application; +use Illuminate\Filesystem\Filesystem; class MigrationServiceProvider extends AbstractServiceProvider { @@ -21,12 +22,12 @@ class MigrationServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) { + $this->app->singleton(MigrationRepositoryInterface::class, function ($app) { return new DatabaseMigrationRepository($app['flarum.db'], 'migrations'); }); $this->app->bind(MigrationCreator::class, function (Application $app) { - return new MigrationCreator($app->make('Illuminate\Filesystem\Filesystem'), $app->basePath()); + return new MigrationCreator($app->make(Filesystem::class), $app->basePath()); }); } } diff --git a/src/Post/PostServiceProvider.php b/src/Post/PostServiceProvider.php index b597f875c..b7cdae086 100644 --- a/src/Post/PostServiceProvider.php +++ b/src/Post/PostServiceProvider.php @@ -26,14 +26,14 @@ class PostServiceProvider extends AbstractServiceProvider $this->registerPostTypes(); $events = $this->app->make('events'); - $events->subscribe('Flarum\Post\PostPolicy'); + $events->subscribe(PostPolicy::class); } public function registerPostTypes() { $models = [ - 'Flarum\Post\CommentPost', - 'Flarum\Post\DiscussionRenamedPost' + CommentPost::class, + DiscussionRenamedPost::class ]; $this->app->make('events')->fire( diff --git a/src/Search/SearchServiceProvider.php b/src/Search/SearchServiceProvider.php index 71d316d54..fbbfefe41 100644 --- a/src/Search/SearchServiceProvider.php +++ b/src/Search/SearchServiceProvider.php @@ -11,9 +11,19 @@ namespace Flarum\Search; +use Flarum\Discussion\Search\DiscussionSearcher; +use Flarum\Discussion\Search\Gambit\AuthorGambit; +use Flarum\Discussion\Search\Gambit\CreatedGambit; +use Flarum\Discussion\Search\Gambit\FulltextGambit as DiscussionFulltextGambit; +use Flarum\Discussion\Search\Gambit\HiddenGambit; +use Flarum\Discussion\Search\Gambit\UnreadGambit; use Flarum\Event\ConfigureDiscussionGambits; use Flarum\Event\ConfigureUserGambits; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\User\Search\Gambit\EmailGambit; +use Flarum\User\Search\Gambit\FulltextGambit as UserFulltextGambit; +use Flarum\User\Search\Gambit\GroupGambit; +use Flarum\User\Search\UserSearcher; use Illuminate\Contracts\Container\Container; class SearchServiceProvider extends AbstractServiceProvider @@ -37,14 +47,14 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerUserGambits() { - $this->app->when('Flarum\User\Search\UserSearcher') - ->needs('Flarum\Search\GambitManager') + $this->app->when(UserSearcher::class) + ->needs(GambitManager::class) ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\User\Search\Gambit\FulltextGambit'); - $gambits->add('Flarum\User\Search\Gambit\EmailGambit'); - $gambits->add('Flarum\User\Search\Gambit\GroupGambit'); + $gambits->setFulltextGambit(UserFulltextGambit::class); + $gambits->add(EmailGambit::class); + $gambits->add(GroupGambit::class); $app->make('events')->fire( new ConfigureUserGambits($gambits) @@ -56,16 +66,16 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerDiscussionGambits() { - $this->app->when('Flarum\Discussion\Search\DiscussionSearcher') - ->needs('Flarum\Search\GambitManager') + $this->app->when(DiscussionSearcher::class) + ->needs(GambitManager::class) ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\Discussion\Search\Gambit\FulltextGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\AuthorGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\CreatedGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\HiddenGambit'); - $gambits->add('Flarum\Discussion\Search\Gambit\UnreadGambit'); + $gambits->setFulltextGambit(DiscussionFulltextGambit::class); + $gambits->add(AuthorGambit::class); + $gambits->add(CreatedGambit::class); + $gambits->add(HiddenGambit::class); + $gambits->add(UnreadGambit::class); $app->make('events')->fire( new ConfigureDiscussionGambits($gambits) diff --git a/src/Settings/SettingsServiceProvider.php b/src/Settings/SettingsServiceProvider.php index 6955083ba..a87cb206f 100644 --- a/src/Settings/SettingsServiceProvider.php +++ b/src/Settings/SettingsServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Settings; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Database\ConnectionInterface; class SettingsServiceProvider extends AbstractServiceProvider { @@ -23,7 +24,7 @@ class SettingsServiceProvider extends AbstractServiceProvider $this->app->singleton(SettingsRepositoryInterface::class, function () { return new MemoryCacheSettingsRepository( new DatabaseSettingsRepository( - $this->app->make('Illuminate\Database\ConnectionInterface') + $this->app->make(ConnectionInterface::class) ) ); }); diff --git a/src/User/UserServiceProvider.php b/src/User/UserServiceProvider.php index 12aae50fb..30e8f823b 100644 --- a/src/User/UserServiceProvider.php +++ b/src/User/UserServiceProvider.php @@ -15,6 +15,9 @@ use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\Auth\Access\Gate as GateContract; +use Illuminate\Contracts\Filesystem\Factory; +use League\Flysystem\FilesystemInterface; use RuntimeException; class UserServiceProvider extends AbstractServiceProvider @@ -36,18 +39,18 @@ class UserServiceProvider extends AbstractServiceProvider }); }); - $this->app->alias('flarum.gate', 'Illuminate\Contracts\Auth\Access\Gate'); + $this->app->alias('flarum.gate', GateContract::class); $this->app->alias('flarum.gate', Gate::class); } protected function registerAvatarsFilesystem() { $avatarsFilesystem = function (Container $app) { - return $app->make('Illuminate\Contracts\Filesystem\Factory')->disk('flarum-avatars')->getDriver(); + return $app->make(Factory::class)->disk('flarum-avatars')->getDriver(); }; $this->app->when(AvatarUploader::class) - ->needs('League\Flysystem\FilesystemInterface') + ->needs(FilesystemInterface::class) ->give($avatarsFilesystem); }