update
This commit is contained in:
40
projects/priceservice/vendor/symfony/messenger/Middleware/ActivationMiddleware.php
vendored
Normal file
40
projects/priceservice/vendor/symfony/messenger/Middleware/ActivationMiddleware.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
|
||||
/**
|
||||
* Execute the inner middleware according to an activation strategy.
|
||||
*
|
||||
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
|
||||
*/
|
||||
class ActivationMiddleware implements MiddlewareInterface
|
||||
{
|
||||
private MiddlewareInterface $inner;
|
||||
private \Closure|bool $activated;
|
||||
|
||||
public function __construct(MiddlewareInterface $inner, bool|callable $activated)
|
||||
{
|
||||
$this->inner = $inner;
|
||||
$this->activated = \is_bool($activated) ? $activated : $activated(...);
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
if (\is_callable($this->activated) ? ($this->activated)($envelope) : $this->activated) {
|
||||
return $this->inner->handle($envelope, $stack);
|
||||
}
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
}
|
||||
39
projects/priceservice/vendor/symfony/messenger/Middleware/AddBusNameStampMiddleware.php
vendored
Normal file
39
projects/priceservice/vendor/symfony/messenger/Middleware/AddBusNameStampMiddleware.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Stamp\BusNameStamp;
|
||||
|
||||
/**
|
||||
* Adds the BusNameStamp to the bus.
|
||||
*
|
||||
* @author Ryan Weaver <ryan@symfonycasts.com>
|
||||
*/
|
||||
class AddBusNameStampMiddleware implements MiddlewareInterface
|
||||
{
|
||||
private string $busName;
|
||||
|
||||
public function __construct(string $busName)
|
||||
{
|
||||
$this->busName = $busName;
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
if (null === $envelope->last(BusNameStamp::class)) {
|
||||
$envelope = $envelope->with(new BusNameStamp($this->busName));
|
||||
}
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
}
|
||||
130
projects/priceservice/vendor/symfony/messenger/Middleware/DispatchAfterCurrentBusMiddleware.php
vendored
Normal file
130
projects/priceservice/vendor/symfony/messenger/Middleware/DispatchAfterCurrentBusMiddleware.php
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
|
||||
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;
|
||||
|
||||
/**
|
||||
* Allow to configure messages to be handled after the current bus is finished.
|
||||
*
|
||||
* I.e, messages dispatched from a handler with a DispatchAfterCurrentBus stamp
|
||||
* will actually be handled once the current message being dispatched is fully
|
||||
* handled.
|
||||
*
|
||||
* For instance, using this middleware before the DoctrineTransactionMiddleware
|
||||
* means sub-dispatched messages with a DispatchAfterCurrentBus stamp would be
|
||||
* handled after the Doctrine transaction has been committed.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class DispatchAfterCurrentBusMiddleware implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @var QueuedEnvelope[] A queue of messages and next middleware
|
||||
*/
|
||||
private array $queue = [];
|
||||
|
||||
/**
|
||||
* @var bool this property is used to signal if we are inside a the first/root call to
|
||||
* MessageBusInterface::dispatch() or if dispatch has been called inside a message handler
|
||||
*/
|
||||
private bool $isRootDispatchCallRunning = false;
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
if (null !== $envelope->last(DispatchAfterCurrentBusStamp::class)) {
|
||||
if ($this->isRootDispatchCallRunning) {
|
||||
$this->queue[] = new QueuedEnvelope($envelope, $stack);
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
|
||||
$envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
|
||||
}
|
||||
|
||||
if ($this->isRootDispatchCallRunning) {
|
||||
/*
|
||||
* A call to MessageBusInterface::dispatch() was made from inside the main bus handling,
|
||||
* but the message does not have the stamp. So, process it like normal.
|
||||
*/
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
|
||||
// First time we get here, mark as inside a "root dispatch" call:
|
||||
$this->isRootDispatchCallRunning = true;
|
||||
try {
|
||||
// Execute the whole middleware stack & message handling for main dispatch:
|
||||
$returnedEnvelope = $stack->next()->handle($envelope, $stack);
|
||||
} catch (\Throwable $exception) {
|
||||
/*
|
||||
* Whenever an exception occurs while handling a message that has
|
||||
* queued other messages, we drop the queued ones.
|
||||
* This is intentional since the queued commands were likely dependent
|
||||
* on the preceding command.
|
||||
*/
|
||||
$this->queue = [];
|
||||
$this->isRootDispatchCallRunning = false;
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
// "Root dispatch" call is finished, dispatch stored messages.
|
||||
$exceptions = [];
|
||||
while (null !== $queueItem = array_shift($this->queue)) {
|
||||
// Save how many messages are left in queue before handling the message
|
||||
$queueLengthBefore = \count($this->queue);
|
||||
try {
|
||||
// Execute the stored messages
|
||||
$queueItem->getStack()->next()->handle($queueItem->getEnvelope(), $queueItem->getStack());
|
||||
} catch (\Exception $exception) {
|
||||
// Gather all exceptions
|
||||
$exceptions[] = $exception;
|
||||
// Restore queue to previous state
|
||||
$this->queue = \array_slice($this->queue, 0, $queueLengthBefore);
|
||||
}
|
||||
}
|
||||
|
||||
$this->isRootDispatchCallRunning = false;
|
||||
if (\count($exceptions) > 0) {
|
||||
throw new DelayedMessageHandlingException($exceptions, $returnedEnvelope);
|
||||
}
|
||||
|
||||
return $returnedEnvelope;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class QueuedEnvelope
|
||||
{
|
||||
private Envelope $envelope;
|
||||
private StackInterface $stack;
|
||||
|
||||
public function __construct(Envelope $envelope, StackInterface $stack)
|
||||
{
|
||||
$this->envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
|
||||
$this->stack = $stack;
|
||||
}
|
||||
|
||||
public function getEnvelope(): Envelope
|
||||
{
|
||||
return $this->envelope;
|
||||
}
|
||||
|
||||
public function getStack(): StackInterface
|
||||
{
|
||||
return $this->stack;
|
||||
}
|
||||
}
|
||||
36
projects/priceservice/vendor/symfony/messenger/Middleware/FailedMessageProcessingMiddleware.php
vendored
Normal file
36
projects/priceservice/vendor/symfony/messenger/Middleware/FailedMessageProcessingMiddleware.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
|
||||
use Symfony\Component\Messenger\Stamp\SentToFailureTransportStamp;
|
||||
|
||||
/**
|
||||
* @author Ryan Weaver <ryan@symfonycasts.com>
|
||||
*/
|
||||
class FailedMessageProcessingMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
// look for "received" messages decorated with the SentToFailureTransportStamp
|
||||
/** @var SentToFailureTransportStamp|null $sentToFailureStamp */
|
||||
$sentToFailureStamp = $envelope->last(SentToFailureTransportStamp::class);
|
||||
if (null !== $sentToFailureStamp && null !== $envelope->last(ReceivedStamp::class)) {
|
||||
// mark the message as "received" from the original transport
|
||||
// this guarantees the same behavior as when originally received
|
||||
$envelope = $envelope->with(new ReceivedStamp($sentToFailureStamp->getOriginalReceiverName()));
|
||||
}
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
}
|
||||
154
projects/priceservice/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php
vendored
Normal file
154
projects/priceservice/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Psr\Log\LoggerAwareTrait;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\HandlerFailedException;
|
||||
use Symfony\Component\Messenger\Exception\LogicException;
|
||||
use Symfony\Component\Messenger\Exception\NoHandlerForMessageException;
|
||||
use Symfony\Component\Messenger\Handler\Acknowledger;
|
||||
use Symfony\Component\Messenger\Handler\HandlerDescriptor;
|
||||
use Symfony\Component\Messenger\Handler\HandlersLocatorInterface;
|
||||
use Symfony\Component\Messenger\Stamp\AckStamp;
|
||||
use Symfony\Component\Messenger\Stamp\FlushBatchHandlersStamp;
|
||||
use Symfony\Component\Messenger\Stamp\HandledStamp;
|
||||
use Symfony\Component\Messenger\Stamp\HandlerArgumentsStamp;
|
||||
use Symfony\Component\Messenger\Stamp\NoAutoAckStamp;
|
||||
|
||||
/**
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*/
|
||||
class HandleMessageMiddleware implements MiddlewareInterface
|
||||
{
|
||||
use LoggerAwareTrait;
|
||||
|
||||
public function __construct(
|
||||
private HandlersLocatorInterface $handlersLocator,
|
||||
private bool $allowNoHandlers = false,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoHandlerForMessageException When no handler is found and $allowNoHandlers is false
|
||||
*/
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
$handler = null;
|
||||
$message = $envelope->getMessage();
|
||||
|
||||
$context = [
|
||||
'class' => $message::class,
|
||||
];
|
||||
|
||||
$exceptions = [];
|
||||
$alreadyHandled = false;
|
||||
foreach ($this->handlersLocator->getHandlers($envelope) as $handlerDescriptor) {
|
||||
if ($this->messageHasAlreadyBeenHandled($envelope, $handlerDescriptor)) {
|
||||
$alreadyHandled = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$handler = $handlerDescriptor->getHandler();
|
||||
$batchHandler = $handlerDescriptor->getBatchHandler();
|
||||
|
||||
/** @var AckStamp $ackStamp */
|
||||
if ($batchHandler && $ackStamp = $envelope->last(AckStamp::class)) {
|
||||
$ack = new Acknowledger(get_debug_type($batchHandler), static function (?\Throwable $e = null, $result = null) use ($envelope, $ackStamp, $handlerDescriptor) {
|
||||
if (null !== $e) {
|
||||
$e = new HandlerFailedException($envelope, [$handlerDescriptor->getName() => $e]);
|
||||
} else {
|
||||
$envelope = $envelope->with(HandledStamp::fromDescriptor($handlerDescriptor, $result));
|
||||
}
|
||||
|
||||
$ackStamp->ack($envelope, $e);
|
||||
});
|
||||
|
||||
$result = $this->callHandler($handler, $message, $ack, $envelope->last(HandlerArgumentsStamp::class));
|
||||
|
||||
if (!\is_int($result) || 0 > $result) {
|
||||
throw new LogicException(sprintf('A handler implementing BatchHandlerInterface must return the size of the current batch as a positive integer, "%s" returned from "%s".', \is_int($result) ? $result : get_debug_type($result), get_debug_type($batchHandler)));
|
||||
}
|
||||
|
||||
if (!$ack->isAcknowledged()) {
|
||||
$envelope = $envelope->with(new NoAutoAckStamp($handlerDescriptor));
|
||||
} elseif ($ack->getError()) {
|
||||
throw $ack->getError();
|
||||
} else {
|
||||
$result = $ack->getResult();
|
||||
}
|
||||
} else {
|
||||
$result = $this->callHandler($handler, $message, null, $envelope->last(HandlerArgumentsStamp::class));
|
||||
}
|
||||
|
||||
$handledStamp = HandledStamp::fromDescriptor($handlerDescriptor, $result);
|
||||
$envelope = $envelope->with($handledStamp);
|
||||
$this->logger?->info('Message {class} handled by {handler}', $context + ['handler' => $handledStamp->getHandlerName()]);
|
||||
} catch (\Throwable $e) {
|
||||
$exceptions[$handlerDescriptor->getName()] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
/** @var FlushBatchHandlersStamp $flushStamp */
|
||||
if ($flushStamp = $envelope->last(FlushBatchHandlersStamp::class)) {
|
||||
/** @var NoAutoAckStamp $stamp */
|
||||
foreach ($envelope->all(NoAutoAckStamp::class) as $stamp) {
|
||||
try {
|
||||
$handler = $stamp->getHandlerDescriptor()->getBatchHandler();
|
||||
$handler->flush($flushStamp->force());
|
||||
} catch (\Throwable $e) {
|
||||
$exceptions[$stamp->getHandlerDescriptor()->getName()] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $handler && !$alreadyHandled) {
|
||||
if (!$this->allowNoHandlers) {
|
||||
throw new NoHandlerForMessageException(sprintf('No handler for message "%s".', $context['class']));
|
||||
}
|
||||
|
||||
$this->logger?->info('No handler for message {class}', $context);
|
||||
}
|
||||
|
||||
if (\count($exceptions)) {
|
||||
throw new HandlerFailedException($envelope, $exceptions);
|
||||
}
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
|
||||
private function messageHasAlreadyBeenHandled(Envelope $envelope, HandlerDescriptor $handlerDescriptor): bool
|
||||
{
|
||||
/** @var HandledStamp $stamp */
|
||||
foreach ($envelope->all(HandledStamp::class) as $stamp) {
|
||||
if ($stamp->getHandlerName() === $handlerDescriptor->getName()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function callHandler(callable $handler, object $message, ?Acknowledger $ack, ?HandlerArgumentsStamp $handlerArgumentsStamp): mixed
|
||||
{
|
||||
$arguments = [$message];
|
||||
if (null !== $ack) {
|
||||
$arguments[] = $ack;
|
||||
}
|
||||
if (null !== $handlerArgumentsStamp) {
|
||||
$arguments = [...$arguments, ...$handlerArgumentsStamp->getAdditionalArguments()];
|
||||
}
|
||||
|
||||
return $handler(...$arguments);
|
||||
}
|
||||
}
|
||||
22
projects/priceservice/vendor/symfony/messenger/Middleware/MiddlewareInterface.php
vendored
Normal file
22
projects/priceservice/vendor/symfony/messenger/Middleware/MiddlewareInterface.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
|
||||
/**
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*/
|
||||
interface MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope;
|
||||
}
|
||||
43
projects/priceservice/vendor/symfony/messenger/Middleware/RejectRedeliveredMessageMiddleware.php
vendored
Normal file
43
projects/priceservice/vendor/symfony/messenger/Middleware/RejectRedeliveredMessageMiddleware.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceivedStamp;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\RejectRedeliveredMessageException;
|
||||
|
||||
/**
|
||||
* Middleware that throws a RejectRedeliveredMessageException when a message is detected that has been redelivered by AMQP.
|
||||
*
|
||||
* The middleware runs before the HandleMessageMiddleware and prevents redelivered messages from being handled directly.
|
||||
* The thrown exception is caught by the worker and will trigger the retry logic according to the retry strategy.
|
||||
*
|
||||
* AMQP redelivers messages when they do not get acknowledged or rejected. This can happen when the connection times out
|
||||
* or an exception is thrown before acknowledging or rejecting. When such errors happen again while handling the
|
||||
* redelivered message, the message would get redelivered again and again. The purpose of this middleware is to prevent
|
||||
* infinite redelivery loops and to unblock the queue by republishing the redelivered messages as retries with a retry
|
||||
* limit and potential delay.
|
||||
*
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
class RejectRedeliveredMessageMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
$amqpReceivedStamp = $envelope->last(AmqpReceivedStamp::class);
|
||||
if ($amqpReceivedStamp instanceof AmqpReceivedStamp && $amqpReceivedStamp->getAmqpEnvelope()->isRedelivery()) {
|
||||
throw new RejectRedeliveredMessageException('Redelivered message from AMQP detected that will be rejected and trigger the retry logic.');
|
||||
}
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
}
|
||||
88
projects/priceservice/vendor/symfony/messenger/Middleware/RouterContextMiddleware.php
vendored
Normal file
88
projects/priceservice/vendor/symfony/messenger/Middleware/RouterContextMiddleware.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Stamp\ConsumedByWorkerStamp;
|
||||
use Symfony\Component\Messenger\Stamp\RouterContextStamp;
|
||||
use Symfony\Component\Routing\RequestContextAwareInterface;
|
||||
|
||||
/**
|
||||
* Restore the Router context when processing the message.
|
||||
*
|
||||
* @author Jérémy Derussé <jeremy@derusse.com>
|
||||
*/
|
||||
class RouterContextMiddleware implements MiddlewareInterface
|
||||
{
|
||||
private RequestContextAwareInterface $router;
|
||||
|
||||
public function __construct(RequestContextAwareInterface $router)
|
||||
{
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
if (!$envelope->last(ConsumedByWorkerStamp::class) || !$contextStamp = $envelope->last(RouterContextStamp::class)) {
|
||||
$context = $this->router->getContext();
|
||||
$envelope = $envelope->with(new RouterContextStamp(
|
||||
$context->getBaseUrl(),
|
||||
$context->getMethod(),
|
||||
$context->getHost(),
|
||||
$context->getScheme(),
|
||||
$context->getHttpPort(),
|
||||
$context->getHttpsPort(),
|
||||
$context->getPathInfo(),
|
||||
$context->getQueryString()
|
||||
));
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
|
||||
$context = $this->router->getContext();
|
||||
$currentBaseUrl = $context->getBaseUrl();
|
||||
$currentMethod = $context->getMethod();
|
||||
$currentHost = $context->getHost();
|
||||
$currentScheme = $context->getScheme();
|
||||
$currentHttpPort = $context->getHttpPort();
|
||||
$currentHttpsPort = $context->getHttpsPort();
|
||||
$currentPathInfo = $context->getPathInfo();
|
||||
$currentQueryString = $context->getQueryString();
|
||||
|
||||
/* @var RouterContextStamp $contextStamp */
|
||||
$context
|
||||
->setBaseUrl($contextStamp->getBaseUrl())
|
||||
->setMethod($contextStamp->getMethod())
|
||||
->setHost($contextStamp->getHost())
|
||||
->setScheme($contextStamp->getScheme())
|
||||
->setHttpPort($contextStamp->getHttpPort())
|
||||
->setHttpsPort($contextStamp->getHttpsPort())
|
||||
->setPathInfo($contextStamp->getPathInfo())
|
||||
->setQueryString($contextStamp->getQueryString())
|
||||
;
|
||||
|
||||
try {
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
} finally {
|
||||
$context
|
||||
->setBaseUrl($currentBaseUrl)
|
||||
->setMethod($currentMethod)
|
||||
->setHost($currentHost)
|
||||
->setScheme($currentScheme)
|
||||
->setHttpPort($currentHttpPort)
|
||||
->setHttpsPort($currentHttpsPort)
|
||||
->setPathInfo($currentPathInfo)
|
||||
->setQueryString($currentQueryString)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
77
projects/priceservice/vendor/symfony/messenger/Middleware/SendMessageMiddleware.php
vendored
Normal file
77
projects/priceservice/vendor/symfony/messenger/Middleware/SendMessageMiddleware.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\Log\LoggerAwareTrait;
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent;
|
||||
use Symfony\Component\Messenger\Exception\NoSenderForMessageException;
|
||||
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
|
||||
use Symfony\Component\Messenger\Stamp\SentStamp;
|
||||
use Symfony\Component\Messenger\Transport\Sender\SendersLocatorInterface;
|
||||
|
||||
/**
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
class SendMessageMiddleware implements MiddlewareInterface
|
||||
{
|
||||
use LoggerAwareTrait;
|
||||
|
||||
public function __construct(
|
||||
private SendersLocatorInterface $sendersLocator,
|
||||
private ?EventDispatcherInterface $eventDispatcher = null,
|
||||
private bool $allowNoSenders = true,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
$context = [
|
||||
'class' => $envelope->getMessage()::class,
|
||||
];
|
||||
|
||||
$sender = null;
|
||||
|
||||
if ($envelope->all(ReceivedStamp::class)) {
|
||||
// it's a received message, do not send it back
|
||||
$this->logger?->info('Received message {class}', $context);
|
||||
} else {
|
||||
$shouldDispatchEvent = true;
|
||||
$senders = $this->sendersLocator->getSenders($envelope);
|
||||
$senders = \is_array($senders) ? $senders : iterator_to_array($senders);
|
||||
foreach ($senders as $alias => $sender) {
|
||||
if (null !== $this->eventDispatcher && $shouldDispatchEvent) {
|
||||
$event = new SendMessageToTransportsEvent($envelope, $senders);
|
||||
$this->eventDispatcher->dispatch($event);
|
||||
$envelope = $event->getEnvelope();
|
||||
$shouldDispatchEvent = false;
|
||||
}
|
||||
|
||||
$this->logger?->info('Sending message {class} with {alias} sender using {sender}', $context + ['alias' => $alias, 'sender' => $sender::class]);
|
||||
$envelope = $sender->send($envelope->with(new SentStamp($sender::class, \is_string($alias) ? $alias : null)));
|
||||
}
|
||||
|
||||
if (!$this->allowNoSenders && !$sender) {
|
||||
throw new NoSenderForMessageException(sprintf('No sender for message "%s".', $context['class']));
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $sender) {
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
|
||||
// message should only be sent and not be handled by the next middleware
|
||||
return $envelope;
|
||||
}
|
||||
}
|
||||
25
projects/priceservice/vendor/symfony/messenger/Middleware/StackInterface.php
vendored
Normal file
25
projects/priceservice/vendor/symfony/messenger/Middleware/StackInterface.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* Implementations must be cloneable, and each clone must unstack the stack independently.
|
||||
*/
|
||||
interface StackInterface
|
||||
{
|
||||
/**
|
||||
* Returns the next middleware to process a message.
|
||||
*/
|
||||
public function next(): MiddlewareInterface;
|
||||
}
|
||||
90
projects/priceservice/vendor/symfony/messenger/Middleware/StackMiddleware.php
vendored
Normal file
90
projects/priceservice/vendor/symfony/messenger/Middleware/StackMiddleware.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class StackMiddleware implements MiddlewareInterface, StackInterface
|
||||
{
|
||||
private MiddlewareStack $stack;
|
||||
private int $offset = 0;
|
||||
|
||||
/**
|
||||
* @param iterable<mixed, MiddlewareInterface>|MiddlewareInterface|null $middlewareIterator
|
||||
*/
|
||||
public function __construct(iterable|MiddlewareInterface|null $middlewareIterator = null)
|
||||
{
|
||||
$this->stack = new MiddlewareStack();
|
||||
|
||||
if (null === $middlewareIterator) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($middlewareIterator instanceof \Iterator) {
|
||||
$this->stack->iterator = $middlewareIterator;
|
||||
} elseif ($middlewareIterator instanceof MiddlewareInterface) {
|
||||
$this->stack->stack[] = $middlewareIterator;
|
||||
} else {
|
||||
$this->stack->iterator = (function () use ($middlewareIterator) {
|
||||
yield from $middlewareIterator;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
public function next(): MiddlewareInterface
|
||||
{
|
||||
if (null === $next = $this->stack->next($this->offset)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
++$this->offset;
|
||||
|
||||
return $next;
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
return $envelope;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class MiddlewareStack
|
||||
{
|
||||
/** @var \Iterator<mixed, MiddlewareInterface>|null */
|
||||
public ?\Iterator $iterator = null;
|
||||
public array $stack = [];
|
||||
|
||||
public function next(int $offset): ?MiddlewareInterface
|
||||
{
|
||||
if (isset($this->stack[$offset])) {
|
||||
return $this->stack[$offset];
|
||||
}
|
||||
|
||||
if (null === $this->iterator) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->iterator->next();
|
||||
|
||||
if (!$this->iterator->valid()) {
|
||||
return $this->iterator = null;
|
||||
}
|
||||
|
||||
return $this->stack[] = $this->iterator->current();
|
||||
}
|
||||
}
|
||||
96
projects/priceservice/vendor/symfony/messenger/Middleware/TraceableMiddleware.php
vendored
Normal file
96
projects/priceservice/vendor/symfony/messenger/Middleware/TraceableMiddleware.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
* Collects some data about a middleware.
|
||||
*
|
||||
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
|
||||
*/
|
||||
class TraceableMiddleware implements MiddlewareInterface
|
||||
{
|
||||
private Stopwatch $stopwatch;
|
||||
private string $busName;
|
||||
private string $eventCategory;
|
||||
|
||||
public function __construct(Stopwatch $stopwatch, string $busName, string $eventCategory = 'messenger.middleware')
|
||||
{
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->busName = $busName;
|
||||
$this->eventCategory = $eventCategory;
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
$stack = new TraceableStack($stack, $this->stopwatch, $this->busName, $this->eventCategory);
|
||||
|
||||
try {
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
} finally {
|
||||
$stack->stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class TraceableStack implements StackInterface
|
||||
{
|
||||
private StackInterface $stack;
|
||||
private Stopwatch $stopwatch;
|
||||
private string $busName;
|
||||
private string $eventCategory;
|
||||
private ?string $currentEvent = null;
|
||||
|
||||
public function __construct(StackInterface $stack, Stopwatch $stopwatch, string $busName, string $eventCategory)
|
||||
{
|
||||
$this->stack = $stack;
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->busName = $busName;
|
||||
$this->eventCategory = $eventCategory;
|
||||
}
|
||||
|
||||
public function next(): MiddlewareInterface
|
||||
{
|
||||
if (null !== $this->currentEvent && $this->stopwatch->isStarted($this->currentEvent)) {
|
||||
$this->stopwatch->stop($this->currentEvent);
|
||||
}
|
||||
|
||||
if ($this->stack === $nextMiddleware = $this->stack->next()) {
|
||||
$this->currentEvent = 'Tail';
|
||||
} else {
|
||||
$this->currentEvent = sprintf('"%s"', get_debug_type($nextMiddleware));
|
||||
}
|
||||
$this->currentEvent .= sprintf(' on "%s"', $this->busName);
|
||||
|
||||
$this->stopwatch->start($this->currentEvent, $this->eventCategory);
|
||||
|
||||
return $nextMiddleware;
|
||||
}
|
||||
|
||||
public function stop(): void
|
||||
{
|
||||
if (null !== $this->currentEvent && $this->stopwatch->isStarted($this->currentEvent)) {
|
||||
$this->stopwatch->stop($this->currentEvent);
|
||||
}
|
||||
$this->currentEvent = null;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->stack = clone $this->stack;
|
||||
}
|
||||
}
|
||||
47
projects/priceservice/vendor/symfony/messenger/Middleware/ValidationMiddleware.php
vendored
Normal file
47
projects/priceservice/vendor/symfony/messenger/Middleware/ValidationMiddleware.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Middleware;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\ValidationFailedException;
|
||||
use Symfony\Component\Messenger\Stamp\ValidationStamp;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class ValidationMiddleware implements MiddlewareInterface
|
||||
{
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
public function __construct(ValidatorInterface $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
||||
{
|
||||
$message = $envelope->getMessage();
|
||||
$groups = null;
|
||||
/** @var ValidationStamp|null $validationStamp */
|
||||
if ($validationStamp = $envelope->last(ValidationStamp::class)) {
|
||||
$groups = $validationStamp->getGroups();
|
||||
}
|
||||
|
||||
$violations = $this->validator->validate($message, null, $groups);
|
||||
if (\count($violations)) {
|
||||
throw new ValidationFailedException($message, $violations, $envelope);
|
||||
}
|
||||
|
||||
return $stack->next()->handle($envelope, $stack);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user