Replace event helper with event dispatcher (#3570)

This commit is contained in:
Ian Morland 2022-07-28 21:09:42 +01:00 committed by GitHub
parent 6911e3a71d
commit 44f30ad51e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 8 deletions

View File

@ -12,6 +12,7 @@ namespace Flarum\Tags\Command;
use Flarum\Tags\Event\Creating;
use Flarum\Tags\Tag;
use Flarum\Tags\TagValidator;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
class CreateTagHandler
@ -22,11 +23,18 @@ class CreateTagHandler
protected $validator;
/**
* @param TagValidator $validator
* @var Dispatcher
*/
public function __construct(TagValidator $validator)
protected $events;
/**
* @param TagValidator $validator
* @param Dispatcher $events
*/
public function __construct(TagValidator $validator, Dispatcher $events)
{
$this->validator = $validator;
$this->events = $events;
}
/**
@ -65,7 +73,7 @@ class CreateTagHandler
}
}
event(new Creating($tag, $actor, $data));
$this->events->dispatch(new Creating($tag, $actor, $data));
$this->validator->assertValid($tag->getAttributes());

View File

@ -11,6 +11,7 @@ namespace Flarum\Tags\Command;
use Flarum\Tags\Event\Deleting;
use Flarum\Tags\TagRepository;
use Illuminate\Contracts\Events\Dispatcher;
class DeleteTagHandler
{
@ -20,11 +21,18 @@ class DeleteTagHandler
protected $tags;
/**
* @param TagRepository $tags
* @var Dispatcher
*/
public function __construct(TagRepository $tags)
protected $events;
/**
* @param TagRepository $tags
* @param Dispatcher $events
*/
public function __construct(TagRepository $tags, Dispatcher $events)
{
$this->tags = $tags;
$this->events = $events;
}
/**
@ -40,7 +48,7 @@ class DeleteTagHandler
$actor->assertCan('delete', $tag);
event(new Deleting($tag, $actor));
$this->events->dispatch(new Deleting($tag, $actor));
$tag->delete();

View File

@ -12,6 +12,7 @@ namespace Flarum\Tags\Command;
use Flarum\Tags\Event\Saving;
use Flarum\Tags\TagRepository;
use Flarum\Tags\TagValidator;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
class EditTagHandler
@ -26,14 +27,21 @@ class EditTagHandler
*/
protected $validator;
/**
* @var Dispatcher
*/
protected $events;
/**
* @param TagRepository $tags
* @param TagValidator $validator
* @param Dispatcher $events
*/
public function __construct(TagRepository $tags, TagValidator $validator)
public function __construct(TagRepository $tags, TagValidator $validator, Dispatcher $events)
{
$this->tags = $tags;
$this->validator = $validator;
$this->events = $events;
}
/**
@ -80,7 +88,7 @@ class EditTagHandler
$tag->is_restricted = (bool) $attributes['isRestricted'];
}
event(new Saving($tag, $actor, $data));
$this->events->dispatch(new Saving($tag, $actor, $data));
$this->validator->assertValid($tag->getDirty());