update
This commit is contained in:
80
projects/priceservice/vendor/symfony/messenger/Handler/Acknowledger.php
vendored
Normal file
80
projects/priceservice/vendor/symfony/messenger/Handler/Acknowledger.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<?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\Handler;
|
||||
|
||||
use Symfony\Component\Messenger\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class Acknowledger
|
||||
{
|
||||
private string $handlerClass;
|
||||
private ?\Closure $ack;
|
||||
private ?\Throwable $error = null;
|
||||
private mixed $result = null;
|
||||
|
||||
/**
|
||||
* @param \Closure(\Throwable|null, mixed):void|null $ack
|
||||
*/
|
||||
public function __construct(string $handlerClass, ?\Closure $ack = null)
|
||||
{
|
||||
$this->handlerClass = $handlerClass;
|
||||
$this->ack = $ack ?? static function () {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $result
|
||||
*/
|
||||
public function ack($result = null): void
|
||||
{
|
||||
$this->doAck(null, $result);
|
||||
}
|
||||
|
||||
public function nack(\Throwable $error): void
|
||||
{
|
||||
$this->doAck($error);
|
||||
}
|
||||
|
||||
public function getError(): ?\Throwable
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getResult(): mixed
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function isAcknowledged(): bool
|
||||
{
|
||||
return null === $this->ack;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if (null !== $this->ack) {
|
||||
throw new LogicException(sprintf('The acknowledger was not called by the "%s" batch handler.', $this->handlerClass));
|
||||
}
|
||||
}
|
||||
|
||||
private function doAck(?\Throwable $e = null, mixed $result = null): void
|
||||
{
|
||||
if (!$ack = $this->ack) {
|
||||
throw new LogicException(sprintf('The acknowledger cannot be called twice by the "%s" batch handler.', $this->handlerClass));
|
||||
}
|
||||
$this->ack = null;
|
||||
$this->error = $e;
|
||||
$this->result = $result;
|
||||
$ack($e, $result);
|
||||
}
|
||||
}
|
||||
34
projects/priceservice/vendor/symfony/messenger/Handler/BatchHandlerInterface.php
vendored
Normal file
34
projects/priceservice/vendor/symfony/messenger/Handler/BatchHandlerInterface.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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\Handler;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface BatchHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @param Acknowledger|null $ack The function to call to ack/nack the $message.
|
||||
* The message should be handled synchronously when null.
|
||||
*
|
||||
* @return mixed The number of pending messages in the batch if $ack is not null,
|
||||
* the result from handling the message otherwise
|
||||
*/
|
||||
// public function __invoke(object $message, ?Acknowledger $ack = null): mixed;
|
||||
|
||||
/**
|
||||
* Flushes any pending buffers.
|
||||
*
|
||||
* @param bool $force Whether flushing is required; it can be skipped if not
|
||||
*/
|
||||
public function flush(bool $force): void;
|
||||
}
|
||||
72
projects/priceservice/vendor/symfony/messenger/Handler/BatchHandlerTrait.php
vendored
Normal file
72
projects/priceservice/vendor/symfony/messenger/Handler/BatchHandlerTrait.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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\Handler;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
trait BatchHandlerTrait
|
||||
{
|
||||
private array $jobs = [];
|
||||
|
||||
public function flush(bool $force): void
|
||||
{
|
||||
if ($jobs = $this->jobs) {
|
||||
$this->jobs = [];
|
||||
$this->process($jobs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Acknowledger|null $ack The function to call to ack/nack the $message.
|
||||
* The message should be handled synchronously when null.
|
||||
*
|
||||
* @return mixed The number of pending messages in the batch if $ack is not null,
|
||||
* the result from handling the message otherwise
|
||||
*/
|
||||
private function handle(object $message, ?Acknowledger $ack): mixed
|
||||
{
|
||||
if (null === $ack) {
|
||||
$ack = new Acknowledger(get_debug_type($this));
|
||||
$this->jobs[] = [$message, $ack];
|
||||
$this->flush(true);
|
||||
|
||||
return $ack->getResult();
|
||||
}
|
||||
|
||||
$this->jobs[] = [$message, $ack];
|
||||
if (!$this->shouldFlush()) {
|
||||
return \count($this->jobs);
|
||||
}
|
||||
|
||||
$this->flush(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function shouldFlush(): bool
|
||||
{
|
||||
return $this->getBatchSize() <= \count($this->jobs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes the jobs in the list.
|
||||
*
|
||||
* @param list<array{0: object, 1: Acknowledger}> $jobs A list of pairs of messages and their corresponding acknowledgers
|
||||
*/
|
||||
abstract private function process(array $jobs): void;
|
||||
|
||||
private function getBatchSize(): int
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
81
projects/priceservice/vendor/symfony/messenger/Handler/HandlerDescriptor.php
vendored
Normal file
81
projects/priceservice/vendor/symfony/messenger/Handler/HandlerDescriptor.php
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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\Handler;
|
||||
|
||||
/**
|
||||
* Describes a handler and the possible associated options, such as `from_transport`, `bus`, etc.
|
||||
*
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*/
|
||||
final class HandlerDescriptor
|
||||
{
|
||||
private \Closure $handler;
|
||||
private string $name;
|
||||
private ?BatchHandlerInterface $batchHandler = null;
|
||||
private array $options;
|
||||
|
||||
public function __construct(callable $handler, array $options = [])
|
||||
{
|
||||
$handler = $handler(...);
|
||||
|
||||
$this->handler = $handler;
|
||||
$this->options = $options;
|
||||
|
||||
$r = new \ReflectionFunction($handler);
|
||||
|
||||
if (str_contains($r->name, '{closure')) {
|
||||
$this->name = 'Closure';
|
||||
} elseif (!$handler = $r->getClosureThis()) {
|
||||
$class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass();
|
||||
|
||||
$this->name = ($class ? $class->name.'::' : '').$r->name;
|
||||
} else {
|
||||
if ($handler instanceof BatchHandlerInterface) {
|
||||
$this->batchHandler = $handler;
|
||||
}
|
||||
|
||||
$this->name = $handler::class.'::'.$r->name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getHandler(): callable
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
$name = $this->name;
|
||||
$alias = $this->options['alias'] ?? null;
|
||||
|
||||
if (null !== $alias) {
|
||||
$name .= '@'.$alias;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function getBatchHandler(): ?BatchHandlerInterface
|
||||
{
|
||||
return $this->batchHandler;
|
||||
}
|
||||
|
||||
public function getOption(string $option): mixed
|
||||
{
|
||||
return $this->options[$option] ?? null;
|
||||
}
|
||||
|
||||
public function getOptions(): array
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
}
|
||||
99
projects/priceservice/vendor/symfony/messenger/Handler/HandlersLocator.php
vendored
Normal file
99
projects/priceservice/vendor/symfony/messenger/Handler/HandlersLocator.php
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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\Handler;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
|
||||
|
||||
/**
|
||||
* Maps a message to a list of handlers.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*/
|
||||
class HandlersLocator implements HandlersLocatorInterface
|
||||
{
|
||||
private array $handlers;
|
||||
|
||||
/**
|
||||
* @param HandlerDescriptor[][]|callable[][] $handlers
|
||||
*/
|
||||
public function __construct(array $handlers)
|
||||
{
|
||||
$this->handlers = $handlers;
|
||||
}
|
||||
|
||||
public function getHandlers(Envelope $envelope): iterable
|
||||
{
|
||||
$seen = [];
|
||||
|
||||
foreach (self::listTypes($envelope) as $type) {
|
||||
foreach ($this->handlers[$type] ?? [] as $handlerDescriptor) {
|
||||
if (\is_callable($handlerDescriptor)) {
|
||||
$handlerDescriptor = new HandlerDescriptor($handlerDescriptor);
|
||||
}
|
||||
|
||||
if (!$this->shouldHandle($envelope, $handlerDescriptor)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $handlerDescriptor->getName();
|
||||
if (\in_array($name, $seen)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[] = $name;
|
||||
|
||||
yield $handlerDescriptor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function listTypes(Envelope $envelope): array
|
||||
{
|
||||
$class = $envelope->getMessage()::class;
|
||||
|
||||
return [$class => $class]
|
||||
+ class_parents($class)
|
||||
+ class_implements($class)
|
||||
+ self::listWildcards($class)
|
||||
+ ['*' => '*'];
|
||||
}
|
||||
|
||||
private static function listWildcards(string $type): array
|
||||
{
|
||||
$type .= '\*';
|
||||
$wildcards = [];
|
||||
while ($i = strrpos($type, '\\', -3)) {
|
||||
$type = substr_replace($type, '\*', $i);
|
||||
$wildcards[$type] = $type;
|
||||
}
|
||||
|
||||
return $wildcards;
|
||||
}
|
||||
|
||||
private function shouldHandle(Envelope $envelope, HandlerDescriptor $handlerDescriptor): bool
|
||||
{
|
||||
if (null === $received = $envelope->last(ReceivedStamp::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (null === $expectedTransport = $handlerDescriptor->getOption('from_transport')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $received->getTransportName() === $expectedTransport;
|
||||
}
|
||||
}
|
||||
29
projects/priceservice/vendor/symfony/messenger/Handler/HandlersLocatorInterface.php
vendored
Normal file
29
projects/priceservice/vendor/symfony/messenger/Handler/HandlersLocatorInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Handler;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
|
||||
/**
|
||||
* Maps a message to a list of handlers.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface HandlersLocatorInterface
|
||||
{
|
||||
/**
|
||||
* Returns the handlers for the given message name.
|
||||
*
|
||||
* @return iterable<int, HandlerDescriptor>
|
||||
*/
|
||||
public function getHandlers(Envelope $envelope): iterable;
|
||||
}
|
||||
25
projects/priceservice/vendor/symfony/messenger/Handler/MessageHandlerInterface.php
vendored
Normal file
25
projects/priceservice/vendor/symfony/messenger/Handler/MessageHandlerInterface.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\Handler;
|
||||
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
/**
|
||||
* Marker interface for message handlers.
|
||||
*
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*
|
||||
* @deprecated since Symfony 6.2, use the {@see AsMessageHandler} attribute instead
|
||||
*/
|
||||
interface MessageHandlerInterface
|
||||
{
|
||||
}
|
||||
53
projects/priceservice/vendor/symfony/messenger/Handler/MessageSubscriberInterface.php
vendored
Normal file
53
projects/priceservice/vendor/symfony/messenger/Handler/MessageSubscriberInterface.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\Handler;
|
||||
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
/**
|
||||
* Handlers can implement this interface to handle multiple messages.
|
||||
*
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*
|
||||
* @deprecated since Symfony 6.2, use the {@see AsMessageHandler} attribute instead
|
||||
*/
|
||||
interface MessageSubscriberInterface extends MessageHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Returns a list of messages to be handled.
|
||||
*
|
||||
* It returns a list of messages like in the following example:
|
||||
*
|
||||
* yield MyMessage::class;
|
||||
*
|
||||
* It can also change the priority per classes.
|
||||
*
|
||||
* yield FirstMessage::class => ['priority' => 0];
|
||||
* yield SecondMessage::class => ['priority' => -10];
|
||||
*
|
||||
* It can also specify a method, a priority, a bus and/or a transport per message:
|
||||
*
|
||||
* yield FirstMessage::class => ['method' => 'firstMessageMethod'];
|
||||
* yield SecondMessage::class => [
|
||||
* 'method' => 'secondMessageMethod',
|
||||
* 'priority' => 20,
|
||||
* 'bus' => 'my_bus_name',
|
||||
* 'from_transport' => 'your_transport_name',
|
||||
* ];
|
||||
*
|
||||
* The benefit of using `yield` instead of returning an array is that you can `yield` multiple times the
|
||||
* same key and therefore subscribe to the same message multiple times with different options.
|
||||
*
|
||||
* The `__invoke` method of the handler will be called as usual with the message to handle.
|
||||
*/
|
||||
public static function getHandledMessages(): iterable;
|
||||
}
|
||||
29
projects/priceservice/vendor/symfony/messenger/Handler/RedispatchMessageHandler.php
vendored
Normal file
29
projects/priceservice/vendor/symfony/messenger/Handler/RedispatchMessageHandler.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Handler;
|
||||
|
||||
use Symfony\Component\Messenger\Message\RedispatchMessage;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
|
||||
|
||||
final class RedispatchMessageHandler
|
||||
{
|
||||
public function __construct(
|
||||
private MessageBusInterface $bus,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(RedispatchMessage $message): void
|
||||
{
|
||||
$this->bus->dispatch($message->envelope, [new TransportNamesStamp($message->transportNames)]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user