mirror of
https://github.com/flarum/core.git
synced 2025-10-21 11:46:05 +02:00
Move command classes to domain namespaces
They will probably be refactored away at a later stage (when we get rid of the command bus). Until then, this lets us remove the Flarum\Core namespace and actually feels quite clean.
This commit is contained in:
63
src/User/Command/DeleteUserHandler.php
Normal file
63
src/User/Command/DeleteUserHandler.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\User\Command;
|
||||
|
||||
use Flarum\Foundation\DispatchEventsTrait;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
use Flarum\User\Event\Deleting;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\UserRepository;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class DeleteUserHandler
|
||||
{
|
||||
use DispatchEventsTrait;
|
||||
use AssertPermissionTrait;
|
||||
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
* @param UserRepository $users
|
||||
*/
|
||||
public function __construct(Dispatcher $events, UserRepository $users)
|
||||
{
|
||||
$this->events = $events;
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeleteUser $command
|
||||
* @return \Flarum\User\User
|
||||
* @throws PermissionDeniedException
|
||||
*/
|
||||
public function handle(DeleteUser $command)
|
||||
{
|
||||
$actor = $command->actor;
|
||||
$user = $this->users->findOrFail($command->userId, $actor);
|
||||
|
||||
$this->assertCan($actor, 'delete', $user);
|
||||
|
||||
$this->events->fire(
|
||||
new Deleting($user, $actor, $command->data)
|
||||
);
|
||||
|
||||
$user->delete();
|
||||
|
||||
$this->dispatchEventsFor($user, $actor);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user