/** * @param OutgoingLogicalMessageContext $context * @param callable $next */ public function invoke($context, callable $next) { $context->setHeader(HeaderTypeEnum::CONTENT_TYPE, $this->messageSerializer->getContentType()); $context->setHeader(HeaderTypeEnum::ENCLOSED_CLASS, $context->getMessage()->getMessageClass()); $body = $this->messageSerializer->serialize($context->getMessage()->getMessageInstance()); $outgoingPhysicalContext = $this->contextFactory->createPhysicalMessageContext($body, $context); $next($outgoingPhysicalContext); }
/** * @param OutgoingLogicalMessageContext $context * @param callable $next */ public function invoke($context, callable $next) { $mutatorIds = $this->mutatorRegistry->getOutgoingLogicalMessageMutatorIds(); if (empty($mutatorIds)) { $next(); return; } $logicalMessage = $context->getMessage(); $messageInstance = $logicalMessage->getMessageInstance(); $mutatorContext = new OutgoingLogicalMessageMutationContext($messageInstance, $context->getHeaders()); foreach ($mutatorIds as $mutatorId) { /** @var OutgoingLogicalMessageMutatorInterface $mutator */ $mutator = $context->getBuilder()->build($mutatorId); $mutator->mutateOutgoing($mutatorContext); } if ($mutatorContext->hasMessageChanged()) { $logicalMessage->updateInstance($mutatorContext->getMessage()); } $context->replaceHeaders($mutatorContext->getHeaders()); $next(); }