From 3b70e2d269e1644d5c0caf455e3da106e9fae4b0 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 20 May 2021 09:27:45 +0200 Subject: [PATCH] [Messenger] Removed deprecated code --- .../Messenger/Bridge/Amqp/CHANGELOG.md | 6 +++ .../Amqp/Tests/Transport/ConnectionTest.php | 50 +++---------------- .../Bridge/Amqp/Transport/Connection.php | 11 ++-- .../Messenger/Bridge/Redis/CHANGELOG.md | 6 +++ .../Bridge/Redis/Transport/Connection.php | 8 +-- src/Symfony/Component/Messenger/CHANGELOG.md | 2 + .../Command/AbstractFailedMessagesCommand.php | 30 ----------- .../Command/FailedMessagesShowCommand.php | 4 -- .../DependencyInjection/MessengerPass.php | 23 ++------- .../Messenger/Stamp/RedeliveryStamp.php | 35 +------------ .../Tests/Stamp/RedeliveryStampTest.php | 2 +- 11 files changed, 32 insertions(+), 145 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/CHANGELOG.md b/src/Symfony/Component/Messenger/Bridge/Amqp/CHANGELOG.md index 1e5bcf3d35193..4c1ade4ea05d4 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/CHANGELOG.md +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +6.0 +--- + + * Remove option `prefetch_count` + * Using invalid options will throw a `LogicException` + 5.3 --- diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php index 0cfcff388e223..3c8a3544a60d0 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php @@ -125,39 +125,27 @@ public function testOptionsAreTakenIntoAccountAndOverwrittenByDsn() ); } - /** - * @group legacy - */ - public function testDeprecationIfInvalidOptionIsPassedWithDsn() + public function testExceptionIfInvalidOptionIsPassedWithDsn() { - $this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.'); + $this->expectExceptionMessage('Invalid option(s) "foo" passed to the AMQP Messenger transport.'); Connection::fromDsn('amqp://host?foo=bar'); } - /** - * @group legacy - */ - public function testDeprecationIfInvalidOptionIsPassedAsArgument() + public function testExceptionIfInvalidOptionIsPassedAsArgument() { - $this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.'); + $this->expectExceptionMessage('Invalid option(s) "foo" passed to the AMQP Messenger transport.'); Connection::fromDsn('amqp://host', ['foo' => 'bar']); } - /** - * @group legacy - */ - public function testDeprecationIfInvalidQueueOptionIsPassed() + public function testExceptionIfInvalidQueueOptionIsPassed() { - $this->expectDeprecation('Since symfony/messenger 5.1: Invalid queue option(s) "foo" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.'); + $this->expectExceptionMessage('Invalid queue option(s) "foo" passed to the AMQP Messenger transport.'); Connection::fromDsn('amqp://host', ['queues' => ['queueName' => ['foo' => 'bar']]]); } - /** - * @group legacy - */ - public function testDeprecationIfInvalidExchangeOptionIsPassed() + public function testExceptionIfInvalidExchangeOptionIsPassed() { - $this->expectDeprecation('Since symfony/messenger 5.1: Invalid exchange option(s) "foo" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.'); + $this->expectExceptionMessage('Invalid exchange option(s) "foo" passed to the AMQP Messenger transport.'); Connection::fromDsn('amqp://host', ['exchange' => ['foo' => 'bar']]); } @@ -439,28 +427,6 @@ public function testItSetupQueuesOnce() $connection->publish('body'); } - /** - * @group legacy - */ - public function testSetChannelPrefetchWhenSetup() - { - $factory = new TestAmqpFactory( - $amqpConnection = $this->createMock(\AMQPConnection::class), - $amqpChannel = $this->createMock(\AMQPChannel::class), - $amqpQueue = $this->createMock(\AMQPQueue::class), - $amqpExchange = $this->createMock(\AMQPExchange::class) - ); - - // makes sure the channel looks connected, so it's not re-created - $amqpChannel->expects($this->any())->method('isConnected')->willReturn(true); - - $amqpChannel->expects($this->never())->method('setPrefetchCount'); - - $this->expectDeprecation('Since symfony/messenger 5.3: The "prefetch_count" option passed to the AMQP Messenger transport has no effect and should not be used.'); - $connection = Connection::fromDsn('amqp://localhost?prefetch_count=2', [], $factory); - $connection->setup(); - } - public function testAutoSetupWithDelayDeclaresExchangeQueuesAndDelay() { $amqpConnection = $this->createMock(\AMQPConnection::class); diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php index e03dc72a472c6..176cd101df022 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php @@ -43,7 +43,6 @@ class Connection 'exchange', 'delay', 'auto_setup', - 'prefetch_count', 'retry', 'persistent', 'frame_max', @@ -238,11 +237,7 @@ public static function fromDsn(string $dsn, array $options = [], AmqpFactory $am private static function validateOptions(array $options): void { if (0 < \count($invalidOptions = array_diff(array_keys($options), self::AVAILABLE_OPTIONS))) { - trigger_deprecation('symfony/messenger', '5.1', 'Invalid option(s) "%s" passed to the AMQP Messenger transport. Passing invalid options is deprecated.', implode('", "', $invalidOptions)); - } - - if (isset($options['prefetch_count'])) { - trigger_deprecation('symfony/messenger', '5.3', 'The "prefetch_count" option passed to the AMQP Messenger transport has no effect and should not be used.'); + throw new LogicException(sprintf('Invalid option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidOptions))); } if (\is_array($options['queues'] ?? false)) { @@ -252,14 +247,14 @@ private static function validateOptions(array $options): void } if (0 < \count($invalidQueueOptions = array_diff(array_keys($queue), self::AVAILABLE_QUEUE_OPTIONS))) { - trigger_deprecation('symfony/messenger', '5.1', 'Invalid queue option(s) "%s" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.', implode('", "', $invalidQueueOptions)); + throw new LogicException(sprintf('Invalid queue option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidQueueOptions))); } } } if (\is_array($options['exchange'] ?? false) && 0 < \count($invalidExchangeOptions = array_diff(array_keys($options['exchange']), self::AVAILABLE_EXCHANGE_OPTIONS))) { - trigger_deprecation('symfony/messenger', '5.1', 'Invalid exchange option(s) "%s" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.', implode('", "', $invalidExchangeOptions)); + throw new LogicException(sprintf('Invalid exchange option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidExchangeOptions))); } } diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md b/src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md index 56df750c519bb..deef51952a9cf 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md +++ b/src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +6.0 +--- + + * Remove option `tls` + * Using invalid options will throw a `LogicException` + 5.3 --- diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php index 5a49b831a3ed7..62116bdfeac65 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php @@ -36,7 +36,6 @@ class Connection 'delete_after_reject' => true, 'stream_max_entries' => 0, // any value higher than 0 defines an approximate maximum number of stream entries 'dbindex' => 0, - 'tls' => false, 'redeliver_timeout' => 3600, // Timeout before redeliver messages still in pending state (seconds) 'claim_interval' => 60000, // Interval by which pending/abandoned messages should be checked 'lazy' => false, @@ -189,11 +188,6 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis|\Re } $tls = 'rediss' === $parsedUrl['scheme']; - if (\array_key_exists('tls', $redisOptions)) { - trigger_deprecation('symfony/redis-messenger', '5.3', 'Providing "tls" parameter is deprecated, use "rediss://" DSN scheme instead'); - $tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN); - unset($redisOptions['tls']); - } $redeliverTimeout = null; if (\array_key_exists('redeliver_timeout', $redisOptions)) { @@ -272,7 +266,7 @@ private static function validateOptions(array $options): void $availableOptions[] = 'serializer'; if (0 < \count($invalidOptions = array_diff(array_keys($options), $availableOptions))) { - trigger_deprecation('symfony/messenger', '5.1', 'Invalid option(s) "%s" passed to the Redis Messenger transport. Passing invalid options is deprecated.', implode('", "', $invalidOptions)); + throw new LogicException(sprintf('Invalid option(s) "%s" passed to the Redis Messenger transport.', implode('", "', $invalidOptions))); } } diff --git a/src/Symfony/Component/Messenger/CHANGELOG.md b/src/Symfony/Component/Messenger/CHANGELOG.md index 70168dae5346b..6dd355899effb 100644 --- a/src/Symfony/Component/Messenger/CHANGELOG.md +++ b/src/Symfony/Component/Messenger/CHANGELOG.md @@ -5,6 +5,8 @@ CHANGELOG --- * Remove deprecated classes `Symfony/Component/Messenger/Transport/AmqpExt`, `Symfony/Component/Messenger/Transport/Doctrine` and `Symfony/Component/Messenger/Transport/Redis`. + * Class `MessengerPass` cannot be configured with constructor arguments + * Remove constructor arguments and getters for `RedeliveryStamp`'s properties `exceptionMessage` and `flattenException` 5.4 --- diff --git a/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php b/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php index 7251ac130c1d0..f2501c928d9e8 100644 --- a/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php @@ -83,7 +83,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io) $lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class); /** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */ $lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class); - $lastRedeliveryStampWithException = $this->getLastRedeliveryStampWithException($envelope, true); $rows = [ ['Class', \get_class($envelope->getMessage())], @@ -109,12 +108,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io) $errorMessage = $lastErrorDetailsStamp->getExceptionMessage(); $errorCode = $lastErrorDetailsStamp->getExceptionCode(); $errorClass = $lastErrorDetailsStamp->getExceptionClass(); - } elseif (null !== $lastRedeliveryStampWithException) { - // Try reading the errorMessage for messages that are still in the queue without the new ErrorDetailStamps. - $errorMessage = $lastRedeliveryStampWithException->getExceptionMessage(); - if (null !== $lastRedeliveryStampWithException->getFlattenException()) { - $errorClass = $lastRedeliveryStampWithException->getFlattenException()->getClass(); - } } $rows = array_merge($rows, [ @@ -144,8 +137,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io) $flattenException = null; if (null !== $lastErrorDetailsStamp) { $flattenException = $lastErrorDetailsStamp->getFlattenException(); - } elseif (null !== $lastRedeliveryStampWithException) { - $flattenException = $lastRedeliveryStampWithException->getFlattenException(); } $io->writeln(null === $flattenException ? '(no data)' : $dump($flattenException)); } else { @@ -177,27 +168,6 @@ protected function getReceiver(string $name = null): ReceiverInterface return $this->failureTransports->get($name); } - protected function getLastRedeliveryStampWithException(Envelope $envelope): ?RedeliveryStamp - { - if (null === \func_get_args()[1]) { - trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getLastRedeliveryStampWithException" method in the "%s" class is deprecated, use the "Envelope::last(%s)" instead.', self::class, ErrorDetailsStamp::class)); - } - - // Use ErrorDetailsStamp instead if it is available - if (null !== $envelope->last(ErrorDetailsStamp::class)) { - return null; - } - - /** @var RedeliveryStamp $stamp */ - foreach (array_reverse($envelope->all(RedeliveryStamp::class)) as $stamp) { - if (null !== $stamp->getExceptionMessage()) { - return $stamp; - } - } - - return null; - } - private function createCloner(): ?ClonerInterface { if (!class_exists(VarCloner::class)) { diff --git a/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php b/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php index c292549e3a9c4..2de252fd2c6f3 100644 --- a/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php +++ b/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php @@ -102,14 +102,10 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in $lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class); /** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */ $lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class); - $lastRedeliveryStampWithException = $this->getLastRedeliveryStampWithException($envelope, true); $errorMessage = ''; if (null !== $lastErrorDetailsStamp) { $errorMessage = $lastErrorDetailsStamp->getExceptionMessage(); - } elseif (null !== $lastRedeliveryStampWithException) { - // Try reading the errorMessage for messages that are still in the queue without the new ErrorDetailStamps. - $errorMessage = $lastRedeliveryStampWithException->getExceptionMessage(); } $rows[] = [ diff --git a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php index 959f053cc8d77..46934063df821 100644 --- a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php +++ b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php @@ -30,28 +30,13 @@ */ class MessengerPass implements CompilerPassInterface { - private $handlerTag; - private $busTag; - private $receiverTag; - - public function __construct(string $handlerTag = 'messenger.message_handler', string $busTag = 'messenger.bus', string $receiverTag = 'messenger.receiver') - { - if (0 < \func_num_args()) { - trigger_deprecation('symfony/messenger', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); - } - - $this->handlerTag = $handlerTag; - $this->busTag = $busTag; - $this->receiverTag = $receiverTag; - } - /** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $busIds = []; - foreach ($container->findTaggedServiceIds($this->busTag) as $busId => $tags) { + foreach ($container->findTaggedServiceIds('messenger.bus') as $busId => $tags) { $busIds[] = $busId; if ($container->hasParameter($busMiddlewareParameter = $busId.'.middleware')) { $this->registerBusMiddleware($container, $busId, $container->getParameter($busMiddlewareParameter)); @@ -76,10 +61,10 @@ private function registerHandlers(ContainerBuilder $container, array $busIds) $handlersByBusAndMessage = []; $handlerToOriginalServiceIdMapping = []; - foreach ($container->findTaggedServiceIds($this->handlerTag, true) as $serviceId => $tags) { + foreach ($container->findTaggedServiceIds('messenger.message_handler', true) as $serviceId => $tags) { foreach ($tags as $tag) { if (isset($tag['bus']) && !\in_array($tag['bus'], $busIds, true)) { - throw new RuntimeException(sprintf('Invalid handler service "%s": bus "%s" specified on the tag "%s" does not exist (known ones are: "%s").', $serviceId, $tag['bus'], $this->handlerTag, implode('", "', $busIds))); + throw new RuntimeException(sprintf('Invalid handler service "%s": bus "%s" specified on the tag "messenger.message_handler" does not exist (known ones are: "%s").', $serviceId, $tag['bus'], implode('", "', $busIds))); } $className = $this->getServiceClass($container, $serviceId); @@ -268,7 +253,7 @@ private function registerReceivers(ContainerBuilder $container, array $busIds) } } - foreach ($container->findTaggedServiceIds($this->receiverTag) as $id => $tags) { + foreach ($container->findTaggedServiceIds('messenger.receiver') as $id => $tags) { $receiverClass = $this->getServiceClass($container, $id); if (!is_subclass_of($receiverClass, ReceiverInterface::class)) { throw new RuntimeException(sprintf('Invalid receiver "%s": class "%s" must implement interface "%s".', $id, $receiverClass, ReceiverInterface::class)); diff --git a/src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php b/src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php index 6da3134abb662..1f7b7cf5a4439 100644 --- a/src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php +++ b/src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Messenger\Stamp; -use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\Messenger\Envelope; /** @@ -21,23 +20,11 @@ final class RedeliveryStamp implements StampInterface { private $retryCount; private $redeliveredAt; - private $exceptionMessage; - private $flattenException; - public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null) + public function __construct(int $retryCount, \DateTimeInterface $redeliveredAt = null) { $this->retryCount = $retryCount; $this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable(); - - if (null !== $exceptionMessage) { - trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$exceptionMessage" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class)); - } - $this->exceptionMessage = $exceptionMessage; - - if (null !== $flattenException) { - trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$flattenException" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class)); - } - $this->flattenException = $flattenException; } public static function getRetryCountFromEnvelope(Envelope $envelope): int @@ -53,26 +40,6 @@ public function getRetryCount(): int return $this->retryCount; } - /** - * @deprecated since Symfony 5.2, use ErrorDetailsStamp instead. - */ - public function getExceptionMessage(): ?string - { - trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getExceptionMessage()" method of the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class)); - - return $this->exceptionMessage; - } - - /** - * @deprecated since Symfony 5.2, use ErrorDetailsStamp instead. - */ - public function getFlattenException(): ?FlattenException - { - trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getFlattenException()" method of the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class)); - - return $this->flattenException; - } - public function getRedeliveredAt(): \DateTimeInterface { return $this->redeliveredAt; diff --git a/src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php b/src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php index fa01b64f9da10..f173d516511ef 100644 --- a/src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php +++ b/src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php @@ -25,7 +25,7 @@ public function testGetters() public function testSerialization() { - $stamp = new RedeliveryStamp(10, null, null, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000')); + $stamp = new RedeliveryStamp(10, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000')); $this->assertSame('2005-08-15T15:52:01+0000', $stamp->getRedeliveredAt()->format(\DateTimeInterface::ISO8601)); } }