Split up old CoreServiceProvider

This commit is contained in:
Franz Liedke 2017-06-24 14:51:42 +02:00
parent ede7e96282
commit 6e8b8ac357
9 changed files with 187 additions and 48 deletions

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum;
use Flarum\Foundation\AbstractServiceProvider;
/**
* @deprecated
*/
class BusServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function boot()
{
$this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) {
return get_class($command).'Handler@handle';
});
}
}

View File

@ -0,0 +1,29 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Discussion;
use Flarum\Foundation\AbstractServiceProvider;
class DiscussionServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function boot()
{
$events = $this->app->make('events');
$events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater');
$events->subscribe('Flarum\Discussion\DiscussionPolicy');
$events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier');
}
}

View File

@ -30,4 +30,14 @@ class ExtensionServiceProvider extends AbstractServiceProvider
$this->app->call($bootstrapper);
}
}
/**
* {@inheritdoc}
*/
public function boot()
{
$events = $this->app->make('events');
$events->subscribe('Flarum\Extension\DefaultLanguagePackGuard');
}
}

View File

@ -190,7 +190,16 @@ abstract class AbstractServer
$config->set('mail.username', $settings->get('mail_username'));
$config->set('mail.password', $settings->get('mail_password'));
$app->register('Flarum\Core\CoreServiceProvider');
$app->register('Flarum\BusServiceProvider');
$app->register('Flarum\Discussion\DiscussionServiceProvider');
$app->register('Flarum\Formatter\FormatterServiceProvider');
$app->register('Flarum\Group\GroupServiceProvider');
$app->register('Flarum\Notification\NotificationServiceProvider');
$app->register('Flarum\Post\PostServiceProvider');
$app->register('Flarum\Search\SearchServiceProvider');
$app->register('Flarum\User\UserServiceProvider');
$app->register('Flarum\Api\ApiServiceProvider');
$app->register('Flarum\Forum\ForumServiceProvider');
$app->register('Flarum\Admin\AdminServiceProvider');

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Frontend;
use Flarum\Foundation\AbstractServiceProvider;
class FrontendServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
}
}

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Group;
use Flarum\Foundation\AbstractServiceProvider;
class GroupServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function boot()
{
$events = $this->app->make('events');
$events->subscribe('Flarum\Group\GroupPolicy');
}
}

View File

@ -171,7 +171,13 @@ class InstallCommand extends AbstractCommand
$this->writeSettings();
$this->application->register('Flarum\Core\CoreServiceProvider');
$this->application->register('Flarum\Formatter\FormatterServiceProvider');
$this->application->register('Flarum\Discussion\DiscussionServiceProvider');
$this->application->register('Flarum\Group\GroupServiceProvider');
$this->application->register('Flarum\Notification\NotificationServiceProvider');
$this->application->register('Flarum\Search\SearchServiceProvider');
$this->application->register('Flarum\Post\PostServiceProvider');
$this->application->register('Flarum\User\UserServiceProvider');
$this->seedGroups();
$this->seedPermissions();

View File

@ -0,0 +1,47 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Post;
use Flarum\Event\ConfigurePostTypes;
use Flarum\Foundation\AbstractServiceProvider;
class PostServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
*/
public function boot()
{
CommentPost::setFormatter($this->app->make('flarum.formatter'));
$this->registerPostTypes();
$events = $this->app->make('events');
$events->subscribe('Flarum\Post\PostPolicy');
}
public function registerPostTypes()
{
$models = [
'Flarum\Post\CommentPost',
'Flarum\Post\DiscussionRenamedPost'
];
$this->app->make('events')->fire(
new ConfigurePostTypes($models)
);
foreach ($models as $model) {
Post::setModel($model::$type, $model);
}
}
}

View File

@ -9,20 +9,14 @@
* file that was distributed with this source code.
*/
namespace Flarum\Core;
namespace Flarum\User;
use Flarum\Post\CommentPost;
use Flarum\Event\ConfigurePostTypes;
use Flarum\Event\ConfigureUserPreferences;
use Flarum\Event\GetPermission;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Post\Post;
use Flarum\User\Gate;
use Flarum\User\User;
use Illuminate\Contracts\Container\Container;
use RuntimeException;
class CoreServiceProvider extends AbstractServiceProvider
class UserServiceProvider extends AbstractServiceProvider
{
/**
* {@inheritdoc}
@ -39,10 +33,6 @@ class CoreServiceProvider extends AbstractServiceProvider
$this->app->alias('flarum.gate', 'Flarum\User\Gate');
$this->registerAvatarsFilesystem();
$this->app->register('Flarum\Notification\Notification\NotificationServiceProvider');
$this->app->register('Flarum\Search\SearchServiceProvider');
$this->app->register('Flarum\Formatter\FormatterServiceProvider');
}
protected function registerAvatarsFilesystem()
@ -69,12 +59,6 @@ class CoreServiceProvider extends AbstractServiceProvider
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
$this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) {
return get_class($command).'Handler@handle';
});
$this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) {
// Fire an event so that core and extension policies can hook into
// this permission query and explicitly grant or deny the
@ -97,46 +81,19 @@ class CoreServiceProvider extends AbstractServiceProvider
return false;
});
$this->registerPostTypes();
CommentPost::setFormatter($this->app->make('flarum.formatter'));
User::setHasher($this->app->make('hash'));
User::setGate($this->app->make('flarum.gate'));
$events = $this->app->make('events');
$events->subscribe('Flarum\Core\Listener\SelfDemotionGuard');
$events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater');
$events->subscribe('Flarum\User\UserMetadataUpdater');
$events->subscribe('Flarum\Extension\DefaultLanguagePackGuard');
$events->subscribe('Flarum\User\EmailConfirmationMailer');
$events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier');
$events->subscribe('Flarum\Discussion\DiscussionPolicy');
$events->subscribe('Flarum\Group\GroupPolicy');
$events->subscribe('Flarum\Post\PostPolicy');
$events->subscribe('Flarum\User\UserMetadataUpdater');
$events->subscribe('Flarum\User\UserPolicy');
$events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']);
}
public function registerPostTypes()
{
$models = [
'Flarum\Post\CommentPost',
'Flarum\Post\DiscussionRenamedPost'
];
$this->app->make('events')->fire(
new ConfigurePostTypes($models)
);
foreach ($models as $model) {
Post::setModel($model::$type, $model);
}
}
/**
* @param ConfigureUserPreferences $event
*/