1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 23:44:27 +02:00
Files
php-flarum/src/Post/Command/DeletePostHandler.php
2020-07-17 15:16:15 +02:00

60 lines
1.3 KiB
PHP

<?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\Post\Command;
use Flarum\Foundation\DispatchEventsTrait;
use Flarum\Post\Event\Deleting;
use Flarum\Post\PostRepository;
use Illuminate\Contracts\Events\Dispatcher;
class DeletePostHandler
{
use DispatchEventsTrait;
/**
* @var \Flarum\Post\PostRepository
*/
protected $posts;
/**
* @param Dispatcher $events
* @param \Flarum\Post\PostRepository $posts
*/
public function __construct(Dispatcher $events, PostRepository $posts)
{
$this->events = $events;
$this->posts = $posts;
}
/**
* @param DeletePost $command
* @return \Flarum\Post\Post
* @throws \Flarum\User\Exception\PermissionDeniedException
*/
public function handle(DeletePost $command)
{
$actor = $command->actor;
$post = $this->posts->findOrFail($command->postId, $actor);
$actor->assertCan('delete', $post);
$this->events->dispatch(
new Deleting($post, $actor, $command->data)
);
$post->delete();
$this->dispatchEventsFor($post, $actor);
return $post;
}
}