2015-08-27 07:40:18 +08:00
|
|
|
<?php
|
2015-08-26 14:48:58 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
2015-02-24 18:03:18 +08:00
|
|
|
|
2015-07-04 10:54:48 +08:00
|
|
|
use Flarum\Core\Users\User;
|
2015-07-18 21:29:47 +08:00
|
|
|
use Flarum\Events\ModelAllow;
|
2015-05-15 15:35:46 +08:00
|
|
|
use Flarum\Support\ServiceProvider;
|
2015-07-01 21:04:11 +08:00
|
|
|
use Flarum\Extend;
|
2015-02-24 18:03:18 +08:00
|
|
|
|
|
|
|
class CoreServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap the application events.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-07-01 21:04:11 +08:00
|
|
|
public function boot()
|
2015-02-24 18:03:18 +08:00
|
|
|
{
|
2015-02-25 13:04:02 +08:00
|
|
|
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
|
2015-02-24 18:03:18 +08:00
|
|
|
|
2015-07-04 10:54:48 +08:00
|
|
|
$this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) {
|
|
|
|
return get_class($command).'Handler@handle';
|
|
|
|
});
|
2015-05-11 10:41:19 +08:00
|
|
|
|
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;
|
|
|
|
}
|
2015-02-24 18:03:18 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the service provider.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2015-07-04 10:54:48 +08:00
|
|
|
$this->app->singleton('flarum.forum', 'Flarum\Core\Forum');
|
2015-02-24 18:03:18 +08:00
|
|
|
|
2015-07-31 18:40:49 +08:00
|
|
|
// FIXME: probably use Illuminate's AggregateServiceProvider
|
2015-07-01 21:04:11 +08:00
|
|
|
// functionality, because it includes the 'provides' stuff.
|
2015-07-04 10:54:48 +08:00
|
|
|
$this->app->register('Flarum\Core\Discussions\DiscussionsServiceProvider');
|
2015-07-01 21:04:11 +08:00
|
|
|
$this->app->register('Flarum\Core\Formatter\FormatterServiceProvider');
|
2015-07-31 18:40:49 +08:00
|
|
|
$this->app->register('Flarum\Core\Groups\GroupsServiceProvider');
|
2015-07-01 21:04:11 +08:00
|
|
|
$this->app->register('Flarum\Core\Notifications\NotificationsServiceProvider');
|
2015-07-04 10:54:48 +08:00
|
|
|
$this->app->register('Flarum\Core\Posts\PostsServiceProvider');
|
|
|
|
$this->app->register('Flarum\Core\Users\UsersServiceProvider');
|
2015-02-24 18:03:18 +08:00
|
|
|
}
|
|
|
|
}
|