CommentInMatchHandler.php
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace FootyRoom\App\Comment;
use FootyRoom\Core\Comment\CommentPolicy;
use FootyRoom\Repositories\Match\MatchRepository;
use FootyRoom\Repositories\UserRepository;
class CommentInMatchHandler
{
/**
* @var \FootyRoom\Core\Comment\CommentingService
*/
protected $commentingService;
/**
* @var \FootyRoom\Repositories\UserRepository
*/
protected $userRepo;
/**
* @var \FootyRoom\Repositories\Match\MatchRepository
*/
protected $matchRepo;
/**
* @var \FootyRoom\Core\Comment\CommentPolicy
*/
protected $commentPolicy;
/**
* Constructor.
*
* @param \FootyRoom\Repositories\Match\MatchRepository $matchRepo
* @param \FootyRoom\Repositories\UserRepository $userRepo
* @param \FootyRoom\App\Comment\CommentingService $commentingService
* @param \FootyRoom\Core\Comment\CommentPolicy $commentPolicy
*/
public function __construct(
MatchRepository $matchRepo,
UserRepository $userRepo,
CommentingService $commentingService,
CommentPolicy $commentPolicy
) {
$this->matchRepo = $matchRepo;
$this->userRepo = $userRepo;
$this->commentingService = $commentingService;
$this->commentPolicy = $commentPolicy;
}
/**
* Posts the comment.
*
* @param \FootyRoom\App\Comment\CommentInMatchCommand $command
*
* @return int
*/
public function handle(CommentInMatchCommand $command)
{
$user = $this->userRepo->findById($command->authorUserId);
$this->commentPolicy->canComment($user, true);
$commentable = $this->matchRepo->findById($command->commentableId);
return $this->commentingService->commentSimple(
$command->content,
$command->images,
$commentable,
$command->parentId,
$command->authorUserId,
$command->authorName
);
}
}