| @@ 36-62 (lines=27) @@ | ||
| 33 | * @param IncomingLogicalMessageContext $context |
|
| 34 | * @param callable $next |
|
| 35 | */ |
|
| 36 | public function invoke($context, callable $next) |
|
| 37 | { |
|
| 38 | $mutatorIds = $this->mutatorRegistry->getIncomingLogicalMessageMutatorIds(); |
|
| 39 | ||
| 40 | if (empty($mutatorIds)) { |
|
| 41 | $next(); |
|
| 42 | return; |
|
| 43 | } |
|
| 44 | ||
| 45 | $logicalMessage = $context->getMessage(); |
|
| 46 | $messageInstance = $logicalMessage->getMessageInstance(); |
|
| 47 | ||
| 48 | $mutatorContext = new IncomingLogicalMessageMutationContext($messageInstance, $context->getHeaders()); |
|
| 49 | ||
| 50 | foreach ($mutatorIds as $mutatorId) { |
|
| 51 | /** @var IncomingLogicalMessageMutatorInterface $mutator */ |
|
| 52 | $mutator = $context->getBuilder()->build($mutatorId); |
|
| 53 | $mutator->mutateIncoming($mutatorContext); |
|
| 54 | } |
|
| 55 | ||
| 56 | if ($mutatorContext->hasMessageChanged()) { |
|
| 57 | $logicalMessage->updateInstance($mutatorContext->getMessage(), $this->messageFactory); |
|
| 58 | } |
|
| 59 | $context->replaceHeaders($mutatorContext->getHeaders()); |
|
| 60 | ||
| 61 | $next(); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * @return string |
|
| @@ 28-54 (lines=27) @@ | ||
| 25 | * @param OutgoingLogicalMessageContext $context |
|
| 26 | * @param callable $next |
|
| 27 | */ |
|
| 28 | public function invoke($context, callable $next) |
|
| 29 | { |
|
| 30 | $mutatorIds = $this->mutatorRegistry->getOutgoingLogicalMessageMutatorIds(); |
|
| 31 | ||
| 32 | if (empty($mutatorIds)) { |
|
| 33 | $next(); |
|
| 34 | return; |
|
| 35 | } |
|
| 36 | ||
| 37 | $logicalMessage = $context->getMessage(); |
|
| 38 | $messageInstance = $logicalMessage->getMessageInstance(); |
|
| 39 | ||
| 40 | $mutatorContext = new OutgoingLogicalMessageMutationContext($messageInstance, $context->getHeaders()); |
|
| 41 | ||
| 42 | foreach ($mutatorIds as $mutatorId) { |
|
| 43 | /** @var OutgoingLogicalMessageMutatorInterface $mutator */ |
|
| 44 | $mutator = $context->getBuilder()->build($mutatorId); |
|
| 45 | $mutator->mutateOutgoing($mutatorContext); |
|
| 46 | } |
|
| 47 | ||
| 48 | if ($mutatorContext->hasMessageChanged()) { |
|
| 49 | $logicalMessage->updateInstance($mutatorContext->getMessage()); |
|
| 50 | } |
|
| 51 | $context->replaceHeaders($mutatorContext->getHeaders()); |
|
| 52 | ||
| 53 | $next(); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @return string |
|