-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
DeleteGroupHandler.php
46 lines (34 loc) · 1000 Bytes
/
DeleteGroupHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Group\Command;
use Flarum\Foundation\DispatchEventsTrait;
use Flarum\Group\Event\Deleting;
use Flarum\Group\Group;
use Flarum\Group\GroupRepository;
use Illuminate\Contracts\Events\Dispatcher;
class DeleteGroupHandler
{
use DispatchEventsTrait;
public function __construct(
protected Dispatcher $events,
protected GroupRepository $groups
) {
}
public function handle(DeleteGroup $command): Group
{
$actor = $command->actor;
$group = $this->groups->findOrFail($command->groupId, $actor);
$actor->assertCan('delete', $group);
$this->events->dispatch(
new Deleting($group, $actor, $command->data)
);
$group->delete();
$this->dispatchEventsFor($group, $actor);
return $group;
}
}