framework/src/Core/CoreServiceProvider.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2015-08-27 07:40:18 +08:00
<?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\Core;
use Flarum\Core\Users\User;
2015-07-18 21:29:47 +08:00
use Flarum\Events\ModelAllow;
use Flarum\Support\ServiceProvider;
use Flarum\Extend;
class CoreServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
$this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) {
return get_class($command).'Handler@handle';
});
2015-07-18 21:29:47 +08:00
$events = $this->app->make('events');
$events->listen(ModelAllow::class, function (ModelAllow $event) {
if ($event->model instanceof Forum &&
$event->actor->hasPermission('forum.'.$event->action)) {
return true;
}
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('flarum.forum', 'Flarum\Core\Forum');
2015-07-31 18:40:49 +08:00
// FIXME: probably use Illuminate's AggregateServiceProvider
// functionality, because it includes the 'provides' stuff.
$this->app->register('Flarum\Core\Discussions\DiscussionsServiceProvider');
$this->app->register('Flarum\Core\Formatter\FormatterServiceProvider');
2015-07-31 18:40:49 +08:00
$this->app->register('Flarum\Core\Groups\GroupsServiceProvider');
$this->app->register('Flarum\Core\Notifications\NotificationsServiceProvider');
$this->app->register('Flarum\Core\Posts\PostsServiceProvider');
$this->app->register('Flarum\Core\Users\UsersServiceProvider');
}
}