1
0
mirror of https://github.com/flarum/core.git synced 2025-10-11 23:14:29 +02:00
Files
php-flarum/src/Discussion/Command/DeleteDiscussionHandler.php
Franz Liedke 5b0d0d9f0f 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.
2017-10-03 18:52:50 +02:00

65 lines
1.6 KiB
PHP

<?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\Discussion\Command;
use Flarum\Discussion\DiscussionRepository;
use Flarum\Discussion\Event\Deleting;
use Flarum\Foundation\DispatchEventsTrait;
use Flarum\User\AssertPermissionTrait;
use Flarum\User\Exception\PermissionDeniedException;
use Illuminate\Contracts\Events\Dispatcher;
class DeleteDiscussionHandler
{
use DispatchEventsTrait;
use AssertPermissionTrait;
/**
* @var \Flarum\Discussion\DiscussionRepository
*/
protected $discussions;
/**
* @param Dispatcher $events
* @param DiscussionRepository $discussions
*/
public function __construct(Dispatcher $events, DiscussionRepository $discussions)
{
$this->events = $events;
$this->discussions = $discussions;
}
/**
* @param DeleteDiscussion $command
* @return \Flarum\Discussion\Discussion
* @throws PermissionDeniedException
*/
public function handle(DeleteDiscussion $command)
{
$actor = $command->actor;
$discussion = $this->discussions->findOrFail($command->discussionId, $actor);
$this->assertCan($actor, 'delete', $discussion);
$this->events->fire(
new Deleting($discussion, $actor, $command->data)
);
$discussion->delete();
$this->dispatchEventsFor($discussion, $actor);
return $discussion;
}
}