|
1
|
|
|
<?php |
|
2
|
|
|
namespace PSB\Core\MessageMutation\Pipeline\Outgoing; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use PSB\Core\MessageMutatorRegistry; |
|
6
|
|
|
use PSB\Core\Pipeline\Outgoing\StageContext\OutgoingPhysicalMessageContext; |
|
7
|
|
|
use PSB\Core\Pipeline\PipelineStepInterface; |
|
8
|
|
|
|
|
9
|
|
View Code Duplication |
class OutgoingPhysicalMessageMutationPipelineStep implements PipelineStepInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var MessageMutatorRegistry |
|
13
|
|
|
*/ |
|
14
|
|
|
private $mutatorRegistry; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* IncomingPhysicalMessageMutationPipelineStep constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param MessageMutatorRegistry $mutatorRegistry |
|
20
|
|
|
*/ |
|
21
|
4 |
|
public function __construct(MessageMutatorRegistry $mutatorRegistry) |
|
22
|
|
|
{ |
|
23
|
4 |
|
$this->mutatorRegistry = $mutatorRegistry; |
|
24
|
4 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param OutgoingPhysicalMessageContext $context |
|
28
|
|
|
* @param callable $next |
|
29
|
|
|
*/ |
|
30
|
2 |
|
public function invoke($context, callable $next) |
|
31
|
|
|
{ |
|
32
|
2 |
|
$mutatorIds = $this->mutatorRegistry->getOutgoingPhysicalMessageMutatorIds(); |
|
33
|
|
|
|
|
34
|
2 |
|
if (empty($mutatorIds)) { |
|
35
|
1 |
|
$next(); |
|
36
|
1 |
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
$physicalMessage = $context->getMessage(); |
|
40
|
1 |
|
$mutatorContext = new OutgoingPhysicalMessageMutationContext( |
|
41
|
1 |
|
$physicalMessage->getBody(), |
|
42
|
1 |
|
$physicalMessage->getHeaders() |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
1 |
|
foreach ($mutatorIds as $mutatorId) { |
|
46
|
|
|
/** @var OutgoingPhysicalMessageMutatorInterface $mutator */ |
|
47
|
1 |
|
$mutator = $context->getBuilder()->build($mutatorId); |
|
48
|
1 |
|
$mutator->mutateOutgoing($mutatorContext); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
$physicalMessage->replaceBody($mutatorContext->getBody()); |
|
52
|
1 |
|
$physicalMessage->replaceHeaders($mutatorContext->getHeaders()); |
|
53
|
|
|
|
|
54
|
1 |
|
$next(); |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public static function getStageContextClass() |
|
61
|
|
|
{ |
|
62
|
1 |
|
return OutgoingPhysicalMessageContext::class; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|