FollowHandler.php
1.21 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
<?php
namespace FootyRoom\App\Subscription;
use FootyRoom\Core\Subscription\Subscription;
use FootyRoom\Repositories\SubscriptionRepository;
class FollowHandler
{
/**
* @var \FootyRoom\Repositories\SubscriptionRepository
*/
protected $subscriptionRepo;
/**
* Constructor.
*
* @param \FootyRoom\Repositories\SubscriptionRepository $subscriptionRepo
*/
public function __construct(SubscriptionRepository $subscriptionRepo)
{
$this->subscriptionRepo = $subscriptionRepo;
}
/**
* Handler.
*
* @param \FootyRoom\App\Subscription\FollowCommand $command
*/
public function handle(FollowCommand $command)
{
$subscription = $this->subscriptionRepo->findOneBy(
$command->subjectId,
$command->subjectType,
$command->userId
);
if (!$subscription) {
$subscription = new Subscription($command->subjectId, $command->subjectType, $command->userId);
$subscription->follow();
$this->subscriptionRepo->create($subscription);
} else {
$subscription->follow();
$this->subscriptionRepo->update($subscription);
}
}
}