mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 13:35:47 +08:00
Replace event helper with event dispatcher (#3570)
This commit is contained in:
parent
6911e3a71d
commit
44f30ad51e
|
@ -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());
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user