|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SmoothPhp\LaravelAdapter\StrongConsistency; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
6
|
|
|
use Illuminate\Contracts\Queue\Queue; |
|
7
|
|
|
use SmoothPhp\Contracts\CommandBus\CommandBus; |
|
8
|
|
|
use SmoothPhp\Contracts\Domain\DomainMessage; |
|
9
|
|
|
use SmoothPhp\Contracts\EventBus\EventListener; |
|
10
|
|
|
use SmoothPhp\Contracts\Serialization\Serializer; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PushEventThroughQueueWithCommandId |
|
14
|
|
|
* @package SmoothPhp\LaravelAdapter\StrongConsistency |
|
15
|
|
|
* @author Simon Bennett <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
final class PushEventThroughQueueWithCommandId implements EventListener |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var Queue */ |
|
20
|
|
|
private $queue; |
|
21
|
|
|
|
|
22
|
|
|
/** @var Serializer */ |
|
23
|
|
|
private $serializer; |
|
24
|
|
|
|
|
25
|
|
|
/** @var NotificationsCommandBus */ |
|
26
|
|
|
private $notificationsCommandBus; |
|
27
|
|
|
/** @var Repository */ |
|
28
|
|
|
private $config; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* PushEventsThroughQueue constructor. |
|
32
|
|
|
* @param Queue $queue |
|
33
|
|
|
* @param Serializer $serializer |
|
34
|
|
|
* @param StrongConsistencyCommandBusMiddleware|CommandBus $notificationsCommandBus |
|
35
|
|
|
* @param Repository $config |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( |
|
38
|
|
|
Queue $queue, |
|
39
|
|
|
Serializer $serializer, |
|
40
|
|
|
StrongConsistencyCommandBusMiddleware $notificationsCommandBus, |
|
41
|
|
|
Repository $config |
|
42
|
|
|
) { |
|
43
|
|
|
$this->queue = $queue; |
|
44
|
|
|
$this->serializer = $serializer; |
|
45
|
|
|
$this->notificationsCommandBus = $notificationsCommandBus; |
|
|
|
|
|
|
46
|
|
|
$this->config = $config; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param DomainMessage $domainMessage |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
View Code Duplication |
public function handle(DomainMessage $domainMessage) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
$this->queue->push( |
|
56
|
|
|
QueueToEventDispatcherWithCommandId::class, |
|
57
|
|
|
[ |
|
58
|
|
|
'uuid' => (string)$domainMessage->getId(), |
|
59
|
|
|
'playhead' => $domainMessage->getPlayHead(), |
|
60
|
|
|
'metadata' => json_encode($this->serializer->serialize($domainMessage->getMetadata())), |
|
61
|
|
|
'payload' => json_encode($this->serializer->serialize($domainMessage->getPayload())), |
|
62
|
|
|
'recorded_on' => (string)$domainMessage->getRecordedOn(), |
|
63
|
|
|
'type' => $domainMessage->getType(), |
|
64
|
|
|
'command_id' => $this->notificationsCommandBus->getLastCommandId(), |
|
65
|
|
|
], |
|
66
|
|
|
$this->config->get('cqrses.queue_name', 'default') |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
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..