adds events to hook into

This commit is contained in:
Daniel Klabbers 2018-04-30 11:19:43 +02:00
parent 7e4e38bb74
commit 4d47a24eff
3 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace Flarum\Suspend\Event;
use Flarum\User\User;
class Suspended
{
/**
* @var User
*/
public $user;
/**
* @var User
*/
public $actor;
public function __construct(User $user, User $actor)
{
$this->user = $user;
$this->actor = $actor;
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Flarum\Suspend\Event;
use Flarum\User\User;
class Unsuspended
{
/**
* @var User
*/
public $user;
/**
* @var User
*/
public $actor;
public function __construct(User $user, User $actor)
{
$this->user = $user;
$this->actor = $actor;
}
}

View File

@ -12,6 +12,8 @@
namespace Flarum\Suspend\Listener;
use DateTime;
use Flarum\Suspend\Event\Suspended;
use Flarum\Suspend\Event\Unsuspended;
use Flarum\Suspend\SuspendValidator;
use Flarum\User\AssertPermissionTrait;
use Flarum\User\Event\Saving;
@ -27,13 +29,18 @@ class SaveSuspensionToDatabase
* @var SuspendValidator
*/
protected $validator;
/**
* @var Dispatcher
*/
protected $events;
/**
* @param SuspendValidator $validator
*/
public function __construct(SuspendValidator $validator)
public function __construct(SuspendValidator $validator, Dispatcher $events)
{
$this->validator = $validator;
$this->events = $events;
}
/**
@ -62,6 +69,14 @@ class SaveSuspensionToDatabase
$user->suspend_until = $attributes['suspendUntil']
? new DateTime($attributes['suspendUntil'])
: null;
if ($user->isDirty('suspend_until')) {
$this->events->dispatch(
$user->suspend_until === null ?
new Unsuspended($user, $actor) :
new Suspended($user, $actor)
);
}
}
}
}