framework/src/Core/Notifications/NotificationsServiceProvider.php

79 lines
1.9 KiB
PHP
Raw Normal View History

<?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\Notifications;
2015-07-18 21:29:47 +08:00
use Flarum\Core\Users\User;
use Flarum\Events\RegisterNotificationTypes;
use Flarum\Support\ServiceProvider;
use Flarum\Extend;
2015-07-18 21:29:47 +08:00
use ReflectionClass;
class NotificationsServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
2015-07-18 21:29:47 +08:00
$events = $this->app->make('events');
2015-07-18 21:29:47 +08:00
$events->subscribe('Flarum\Core\Notifications\Listeners\DiscussionRenamedNotifier');
$this->registerNotificationTypes();
}
/**
* Register notification types.
*
* @return void
*/
public function registerNotificationTypes()
{
$blueprints = [
'Flarum\Core\Notifications\DiscussionRenamedBlueprint' => ['alert']
];
event(new RegisterNotificationTypes($blueprints));
foreach ($blueprints as $blueprint => $enabled) {
Notification::setSubjectModel(
$type = $blueprint::getType(),
$blueprint::getSubjectModel()
);
User::addPreference(
User::getNotificationPreferenceKey($type, 'alert'),
'boolval',
in_array('alert', $enabled)
);
if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Core\Notifications\MailableBlueprint')) {
User::addPreference(
User::getNotificationPreferenceKey($type, 'email'),
'boolval',
in_array('email', $enabled)
);
}
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
}