1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
namespace SmoothPhp\LaravelAdapter\StrongConsistency; |
3
|
|
|
|
4
|
|
|
use FlixPremiere\Laravel\CommandNotfication\CommandBus\NotificationsCommandBus; |
5
|
|
|
use Illuminate\Contracts\Queue\Queue; |
6
|
|
|
use SmoothPhp\Contracts\CommandBus\CommandBus; |
7
|
|
|
use SmoothPhp\Contracts\Domain\DomainMessage; |
8
|
|
|
use SmoothPhp\Contracts\EventBus\EventListener; |
9
|
|
|
use SmoothPhp\Contracts\Serialization\Serializer; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class PushEventThroughQueueWithCommandId |
13
|
|
|
* @package SmoothPhp\LaravelAdapter\StrongConsistency |
14
|
|
|
* @author Simon Bennett <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
final class PushEventThroughQueueWithCommandId implements EventListener |
17
|
|
|
{ |
18
|
|
|
/** @var Queue */ |
19
|
|
|
private $queue; |
20
|
|
|
|
21
|
|
|
/** @var Serializer */ |
22
|
|
|
private $serializer; |
23
|
|
|
|
24
|
|
|
/** @var NotificationsCommandBus */ |
25
|
|
|
private $notificationsCommandBus; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* PushEventsThroughQueue constructor. |
29
|
|
|
* @param Queue $queue |
30
|
|
|
* @param Serializer $serializer |
31
|
|
|
* @param StrongConsistencyCommandBus|CommandBus $notificationsCommandBus |
32
|
|
|
*/ |
33
|
|
|
public function __construct(Queue $queue, Serializer $serializer, CommandBus $notificationsCommandBus) |
34
|
|
|
{ |
35
|
|
|
$this->queue = $queue; |
36
|
|
|
$this->serializer = $serializer; |
37
|
|
|
$this->notificationsCommandBus = $notificationsCommandBus; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param DomainMessage $domainMessage |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function handle(DomainMessage $domainMessage) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->queue->push( |
47
|
|
|
QueueToEventDispatcherWithCommandId::class, |
48
|
|
|
[ |
49
|
|
|
'uuid' => (string)$domainMessage->getId(), |
50
|
|
|
'playhead' => $domainMessage->getPlayHead(), |
51
|
|
|
'metadata' => json_encode($this->serializer->serialize($domainMessage->getMetadata())), |
52
|
|
|
'payload' => json_encode($this->serializer->serialize($domainMessage->getPayload())), |
53
|
|
|
'recorded_on' => (string)$domainMessage->getRecordedOn(), |
54
|
|
|
'type' => $domainMessage->getType(), |
55
|
|
|
'command_id' => $this->notificationsCommandBus->getLastCommandId(), |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..