1
|
|
|
<?php |
2
|
|
|
namespace PSB\Core; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use PSB\Core\Pipeline\BusOperations; |
6
|
|
|
use PSB\Core\Pipeline\PipelineRootStageContext; |
7
|
|
|
|
8
|
|
|
class BusContext implements BusContextInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var PipelineRootStageContext |
12
|
|
|
*/ |
13
|
|
|
private $rootContext; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var BusOperations |
17
|
|
|
*/ |
18
|
|
|
private $busOperations; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var OutgoingOptionsFactory |
22
|
|
|
*/ |
23
|
|
|
private $outgoingOptionsFactory; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param PipelineRootStageContext $rootContext |
27
|
|
|
* @param BusOperations $busOperations |
28
|
|
|
* @param OutgoingOptionsFactory $outgoingOptionsFactory |
29
|
|
|
*/ |
30
|
10 |
|
public function __construct( |
31
|
|
|
PipelineRootStageContext $rootContext, |
32
|
|
|
BusOperations $busOperations, |
33
|
|
|
OutgoingOptionsFactory $outgoingOptionsFactory |
34
|
|
|
) { |
35
|
10 |
|
$this->rootContext = $rootContext; |
36
|
10 |
|
$this->busOperations = $busOperations; |
37
|
10 |
|
$this->outgoingOptionsFactory = $outgoingOptionsFactory; |
38
|
10 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param object $message |
42
|
|
|
* @param SendOptions|null $options |
43
|
|
|
*/ |
44
|
3 |
|
public function send($message, SendOptions $options = null) |
45
|
|
|
{ |
46
|
3 |
|
$options = $options ?: $this->outgoingOptionsFactory->createSendOptions(); |
47
|
|
|
|
48
|
3 |
|
$this->busOperations->send($message, $options, $this->rootContext); |
49
|
3 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param object $message |
53
|
|
|
* @param SendOptions|null $options |
54
|
|
|
*/ |
55
|
1 |
View Code Duplication |
public function sendLocal($message, SendOptions $options = null) |
56
|
|
|
{ |
57
|
1 |
|
$options = $options ?: $this->outgoingOptionsFactory->createSendOptions(); |
58
|
1 |
|
$options->routeToLocalEndpointInstance(); |
59
|
|
|
|
60
|
1 |
|
$this->send($message, $options); |
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param object $message |
65
|
|
|
* @param PublishOptions|null $options |
66
|
|
|
*/ |
67
|
2 |
|
public function publish($message, PublishOptions $options = null) |
68
|
|
|
{ |
69
|
2 |
|
$options = $options ?: $this->outgoingOptionsFactory->createPublishOptions(); |
70
|
|
|
|
71
|
2 |
|
$this->busOperations->publish($message, $options, $this->rootContext); |
72
|
2 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $eventFqcn |
76
|
|
|
* @param SubscribeOptions|null $options |
77
|
|
|
*/ |
78
|
2 |
|
public function subscribe($eventFqcn, SubscribeOptions $options = null) |
79
|
|
|
{ |
80
|
2 |
|
$options = $options ?: $this->outgoingOptionsFactory->createSubscribeOptions(); |
81
|
|
|
|
82
|
2 |
|
$this->busOperations->subscribe($eventFqcn, $options, $this->rootContext); |
83
|
2 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $eventFqcn |
87
|
|
|
* @param UnsubscribeOptions|null $options |
88
|
|
|
*/ |
89
|
2 |
|
public function unsubscribe($eventFqcn, UnsubscribeOptions $options = null) |
90
|
|
|
{ |
91
|
2 |
|
$options = $options ?: $this->outgoingOptionsFactory->createUnsubscribeOptions(); |
92
|
|
|
|
93
|
2 |
|
$this->busOperations->unsubscribe($eventFqcn, $options, $this->rootContext); |
94
|
2 |
|
} |
95
|
|
|
} |
96
|
|
|
|