CommentInProfileWallHandler.php
1.94 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\WallRepository;
use FootyRoom\Repositories\UserRepository;
class CommentInProfileWallHandler
{
/**
* @var \FootyRoom\Repositories\WallRepository
*/
protected $wallPostRepo;
/**
* @var \FootyRoom\Repositories\UserRepository
*/
protected $userRepo;
/**
* @var \FootyRoom\Core\Comment\CommentingService
*/
protected $commentingService;
/**
* @var \FootyRoom\Core\Comment\CommentPolicy
*/
protected $commentPolicy;
/**
* Constructor.
*
* @param \FootyRoom\Repositories\WallRepository $wallPostRepo
* @param \FootyRoom\Repositories\UserRepository $userRepo
* @param \FootyRoom\Core\Comment\CommentingService $commentingService
* @param \FootyRoom\Core\Comment\CommentPolicy $commentPolicy
*/
public function __construct(
WallRepository $wallPostRepo,
UserRepository $userRepo,
CommentingService $commentingService,
CommentPolicy $commentPolicy
) {
$this->wallPostRepo = $wallPostRepo;
$this->userRepo = $userRepo;
$this->commentingService = $commentingService;
$this->commentPolicy = $commentPolicy;
}
/**
* Handler.
*
* @param \FootyRoom\App\Comment\CommentInProfileWallCommand $command
*
* @return int Id of new comment.
*/
public function handle(CommentInProfileWallCommand $command)
{
$user = $this->userRepo->findById($command->authorUserId);
$this->commentPolicy->canComment($user, true);
$wall = $this->wallPostRepo->findByUserId($command->commentableId);
return $this->commentingService->commentSimple(
$command->content,
$command->images,
$wall,
$command->parentId,
$command->authorUserId,
$command->authorName
);
}
}