mirror of
https://github.com/flarum/core.git
synced 2025-10-13 07:54:25 +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/Post/Command/DeletePostHandler.php
Normal file
63
src/Post/Command/DeletePostHandler.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\Post\Command;
|
||||
|
||||
use Flarum\Foundation\DispatchEventsTrait;
|
||||
use Flarum\Post\Event\Deleting;
|
||||
use Flarum\Post\PostRepository;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class DeletePostHandler
|
||||
{
|
||||
use DispatchEventsTrait;
|
||||
use AssertPermissionTrait;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
$this->assertCan($actor, 'delete', $post);
|
||||
|
||||
$this->events->fire(
|
||||
new Deleting($post, $actor, $command->data)
|
||||
);
|
||||
|
||||
$post->delete();
|
||||
|
||||
$this->dispatchEventsFor($post, $actor);
|
||||
|
||||
return $post;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user