mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 04:33:47 +08:00
adds events to hook into
This commit is contained in:
parent
7e4e38bb74
commit
4d47a24eff
23
extensions/suspend/src/Event/Suspended.php
Normal file
23
extensions/suspend/src/Event/Suspended.php
Normal 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;
|
||||
}
|
||||
}
|
23
extensions/suspend/src/Event/Unsuspended.php
Normal file
23
extensions/suspend/src/Event/Unsuspended.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user