Use class constant to get qualified class names

This commit is contained in:
Franz Liedke 2018-12-14 01:47:54 +01:00
parent 5c9fa4c62d
commit 3e0cd3a21f
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4
6 changed files with 44 additions and 26 deletions

View File

@ -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'));
}
}

View File

@ -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());
});
}
}

View File

@ -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(

View File

@ -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)

View File

@ -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)
)
);
});

View File

@ -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);
}