1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 16:34:26 +02:00
Files
php-flarum/src/Core/Posts/Commands/DeletePostHandler.php
2015-08-27 01:40:18 +02:00

55 lines
1.1 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\Core\Posts\Commands;
use Flarum\Core\Posts\PostRepository;
use Flarum\Events\PostWillBeDeleted;
use Flarum\Core\Support\DispatchesEvents;
class DeletePostHandler
{
use DispatchesEvents;
/**
* @var PostRepository
*/
protected $posts;
/**
* @param PostRepository $posts
*/
public function __construct(PostRepository $posts)
{
$this->posts = $posts;
}
/**
* @param DeletePost $command
* @return \Flarum\Core\Posts\Post
*/
public function handle(DeletePost $command)
{
$actor = $command->actor;
$post = $this->posts->findOrFail($command->postId, $actor);
$post->assertCan($actor, 'delete');
event(new PostWillBeDeleted($post, $actor, $command->data));
$post->delete();
$this->dispatchEventsFor($post);
return $post;
}
}