8000 [Messenger] Removed deprecated code · symfony/symfony@3b70e2d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b70e2d

Browse files
committed
[Messenger] Removed deprecated code
1 parent 0eb382a commit 3b70e2d

File tree

11 files changed

+32
-145
lines changed

11 files changed

+32
-145
lines changed

src/Symfony/Component/Messenger/Bridge/Amqp/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
6.0
5+
---
6+
7+
* Remove option `prefetch_count`
8+
* Using invalid options will throw a `LogicException`
9+
410
5.3
511
---
612

src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -125,39 +125,27 @@ public function testOptionsAreTakenIntoAccountAndOverwrittenByDsn()
125125
);
126126
}
127127

128-
/**
129-
* @group legacy
130-
*/
131-
public function testDeprecationIfInvalidOptionIsPassedWithDsn()
128+
public function testExceptionIfInvalidOptionIsPassedWithDsn()
132129
{
133-
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.');
130+
$this->expectExceptionMessage('Invalid option(s) "foo" passed to the AMQP Messenger transport.');
134131
Connection::fromDsn('amqp://host?foo=bar');
135132
}
136133

137-
/**
138-
* @group legacy
139-
*/
140-
public function testDeprecationIfInvalidOptionIsPassedAsArgument()
134+
public function testExceptionIfInvalidOptionIsPassedAsArgument()
141135
{
142-
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.');
136+
$this->expectExceptionMessage('Invalid option(s) "foo" passed to the AMQP Messenger transport.');
143137
Connection::fromDsn('amqp://host', ['foo' => 'bar']);
144138
}
145139

146-
/**
147-
* @group legacy
148-
*/
149-
public function testDeprecationIfInvalidQueueOptionIsPassed()
140+
public function testExceptionIfInvalidQueueOptionIsPassed()
150141
{
151-
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid queue option(s) "foo" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.');
142+
$this->expectExceptionMessage('Invalid queue option(s) "foo" passed to the AMQP Messenger transport.');
152143
Connection::fromDsn('amqp://host', ['queues' => ['queueName' => ['foo' => 'bar']]]);
153144
}
154145

155-
/**
156-
* @group legacy
157-
*/
158-
public function testDeprecationIfInvalidExchangeOptionIsPassed()
146+
public function testExceptionIfInvalidExchangeOptionIsPassed()
159147
{
160-
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid exchange option(s) "foo" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.');
148+
$this->expectExceptionMessage('Invalid exchange option(s) "foo" passed to the AMQP Messenger transport.');
161149
Connection::fromDsn('amqp://host', ['exchange' => ['foo' => 'bar']]);
162150
}
163151

@@ -439,28 +427,6 @@ public function testItSetupQueuesOnce()
439427
$connection->publish('body');
440428
}
441429

442-
/**
443-
* @group legacy
444-
*/
445-
public function testSetChannelPrefetchWhenSetup()
446-
{
447-
$factory = new TestAmqpFactory(
448-
$amqpConnection = $this->createMock(\AMQPConnection::class),
449-
$amqpChannel = $this->createMock(\AMQPChannel::class),
450-
$amqpQueue = $this->createMock(\AMQPQueue::class),
451-
$amqpExchange = $this->createMock(\AMQPExchange::class)
452-
);
453-
454-
// makes sure the channel looks connected, so it's not re-created
455-
$amqpChannel->expects($this->any())->method('isConnected')->willReturn(true);
456-
457-
$amqpChannel->expects($this->never())->method('setPrefetchCount');
458-
459-
$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.');
460-
$connection = Connection::fromDsn('amqp://localhost?prefetch_count=2', [], $factory);
461-
$connection->setup();
462-
}
463-
464430
public function testAutoSetupWithDelayDeclaresExchangeQueuesAndDelay()
465431
{
466432
$amqpConnection = $this->createMock(\AMQPConnection::class);

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Connection
4343
'exchange',
4444
'delay',
4545
'auto_setup',
46-
'prefetch_count',
4746
'retry',
4847
'persistent',
4948
'frame_max',
@@ -238,11 +237,7 @@ public static function fromDsn(string $dsn, array $options = [], AmqpFactory $am
238237
private static function validateOptions(array $options): void
239238
{
240239
if (0 < \count($invalidOptions = array_diff(array_keys($options), self::AVAILABLE_OPTIONS))) {
241-
trigger_deprecation('symfony/messenger', '5.1', 'Invalid option(s) "%s" passed to the AMQP Messenger transport. Passing invalid options is deprecated.', implode('", "', $invalidOptions));
242-
}
243-
244-
if (isset($options['prefetch_count'])) {
245-
trigger_deprecation('symfony/messenger', '5.3', 'The "prefetch_count" option passed to the AMQP Messenger transport has no effect and should not be used.');
240+
throw new LogicException(sprintf('Invalid option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidOptions)));
246241
}
247242

248243
if (\is_array($options['queues'] ?? false)) {
@@ -252,14 +247,14 @@ private static function validateOptions(array $options): void
252247
}
253248

254249
if (0 < \count($invalidQueueOptions = array_diff(array_keys($queue), self::AVAILABLE_QUEUE_OPTIONS))) {
255-
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));
250+
throw new LogicException(sprintf('Invalid queue option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidQueueOptions)));
256251
}
257252
}
258253
}
259254

260255
if (\is_array($options['exchange'] ?? false)
261256
&& 0 < \count($invalidExchangeOptions = array_diff(array_keys($options['exchange']), self::AVAILABLE_EXCHANGE_OPTIONS))) {
262-
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));
257+
throw new LogicException(sprintf('Invalid exchange option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidExchangeOptions)));
263258
}
264259
}
265260

src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
6.0
5+
---
6+
7+
* Remove option `tls`
8+
* Using invalid options will throw a `LogicException`
9+
410
5.3
511
---
612

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Connection
3636
'delete_after_reject' => true,
3737
'stream_max_entries' => 0, // any value higher than 0 defines an approximate maximum number of stream entries
3838
'dbindex' => 0,
39-
'tls' => false,
4039
'redeliver_timeout' => 3600, // Timeout before redeliver messages still in pending state (seconds)
4140
'claim_interval' => 60000, // Interval by which pending/abandoned messages should be checked
4241
'lazy' => false,
@@ -189,11 +188,6 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis|\Re
189188
}
190189

191190
$tls = 'rediss' === $parsedUrl['scheme'];
192-
if (\array_key_exists('tls', $redisOptions)) {
193-
trigger_deprecation('symfony/redis-messenger', '5.3', 'Providing "tls" parameter is deprecated, use "rediss://" DSN scheme instead');
194-
$tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN);
195-
unset($redisOptions['tls']);
196-
}
197191

198192
$redeliverTimeout = null;
199193
if (\array_key_exists('redeliver_timeout', $redisOptions)) {
@@ -272,7 +266,7 @@ private static function validateOptions(array $options): void
272266
$availableOptions[] = 'serializer';
273267

274268
if (0 < \count($invalidOptions = array_diff(array_keys($options), $availableOptions))) {
275-
trigger_deprecation('symfony/messenger', '5.1', 'Invalid option(s) "%s" passed to the Redis Messenger transport. Passing invalid options is deprecated.', implode('", "', $invalidOptions));
269+
throw new LogicException(sprintf('Invalid option(s) "%s" passed to the Redis Messenger transport.', implode('", "', $invalidOptions)));
276270
}
277271
}
278272

src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55
---
66

77
* Remove deprecated classes `Symfony/Component/Messenger/Transport/AmqpExt`, `Symfony/Component/Messenger/Transport/Doctrine` and `Symfony/Component/Messenger/Transport/Redis`.
8+
* Class `MessengerPass` cannot be configured with constructor arguments
9+
* Remove constructor arguments and getters for `RedeliveryStamp`'s properties `exceptionMessage` and `flattenException`
810

911
5.4
1012
---

src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io)
8383
$lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class);
8484
/** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */
8585
$lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class);
86-
$lastRedeliveryStampWithException = $this->getLastRedeliveryStampWithException($envelope, true);
8786

8887
$rows = [
8988
['Class', \get_class($envelope->getMessage())],
@@ -109,12 +108,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io)
109108
$errorMessage = $lastErrorDetailsStamp->getExceptionMessage();
110109
$errorCode = $lastErrorDetailsStamp->getExceptionCode();
111110
$errorClass = $lastErrorDetailsStamp->getExceptionClass();
112-
} elseif (null !== $lastRedeliveryStampWithException) {
113-
// Try reading the errorMessage for messages that are still in the queue without the new ErrorDetailStamps.
114-
$errorMessage = $lastRedeliveryStampWithException->getExceptionMessage();
115-
if (null !== $lastRedeliveryStampWithException->getFlattenException()) {
116-
$errorClass = $lastRedeliveryStampWithException->getFlattenException()->getClass();
117-
}
118111
}
119112

120113
$rows = array_merge($rows, [
@@ -144,8 +137,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io)
144137
$flattenException = null;
145138
if (null !== $lastErrorDetailsStamp) {
146139
$flattenException = $lastErrorDetailsStamp->getFlattenException();
147-
} elseif (null !== $lastRedeliveryStampWithException) {
148-
$flattenException = $lastRedeliveryStampWithException->getFlattenException();
149140
}
150141
$io->writeln(null === $flattenException ? '(no data)' : $dump($flattenException));
151142
} else {
@@ -177,27 +168,6 @@ protected function getReceiver(string $name = null): ReceiverInterface
177168
return $this->failureTransports->get($name);
178169
}
179170

180-
protected function getLastRedeliveryStampWithException(Envelope $envelope): ?RedeliveryStamp
181-
{
182-
if (null === \func_get_args()[1]) {
183-
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));
184-
}
185-
186-
// Use ErrorDetailsStamp instead if it is available
187-
if (null !== $envelope->last(ErrorDetailsStamp::class)) {
188-
return null;
189-
}
190-
191-
/** @var RedeliveryStamp $stamp */
192-
foreach (array_reverse($envelope->all(RedeliveryStamp::class)) as $stamp) {
193-
if (null !== $stamp->getExceptionMessage()) {
194-
return $stamp;
195-
}
196-
}
197-
198-
return null;
199-
}
200-
201171
private function createCloner(): ?ClonerInterface
202172
{
203173
if (!class_exists(VarCloner::class)) {

src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,10 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in
102102
$lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class);
103103
/** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */
104104
$lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class);
105-
$lastRedeliveryStampWithException = $this->getLastRedeliveryStampWithException($envelope, true);
106105

107106
$errorMessage = '';
108107
if (null !== $lastErrorDetailsStamp) {
109108
$errorMessage = $lastErrorDetailsStamp->getExceptionMessage();
110-
} elseif (null !== $lastRedeliveryStampWithException) {
111-
// Try reading the errorMessage for messages that are still in the queue without the new ErrorDetailStamps.
112-
$errorMessage = $lastRedeliveryStampWithException->getExceptionMessage();
113109
}
114110

115111
$rows[] = [

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,13 @@
3030
*/
3131
class MessengerPass implements CompilerPassInterface
3232
{
33-
private $handlerTag;
34-
private $busTag;
35-
private $receiverTag;
36-
37-
public function __construct(string $handlerTag = 'messenger.message_handler', string $busTag = 'messenger.bus', string $receiverTag = 'messenger.receiver')
38-
{
39-
if (0 < \func_num_args()) {
40-
trigger_deprecation('symfony/messenger', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
41-
}
42-
43-
$this->handlerTag = $handlerTag;
44-
$this->busTag = $busTag;
45-
$this->receiverTag = $receiverTag;
46-
}
47-
4833
/**
4934
* {@inheritdoc}
5035
*/
5136
public function process(ContainerBuilder $container)
5237
{
5338
$busIds = [];
54-
foreach ($container->findTaggedServiceIds($this->busTag) as $busId => $tags) {
39+
foreach ($container->findTaggedServiceIds('messenger.bus') as $busId => $tags) {
5540
$busIds[] = $busId;
5641
if ($container->hasParameter($busMiddlewareParameter = $busId.'.middleware')) {
5742
$this->registerBusMiddleware($container, $busId, $container->getParameter($busMiddlewareParameter));
@@ -76,10 +61,10 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
7661
$handlersByBusAndMessage = [];
7762
$handlerToOriginalServiceIdMapping = [];
7863

79-
foreach ($container->findTaggedServiceIds($this->handlerTag, true) as $serviceId => $tags) {
64+
foreach ($container->findTaggedServiceIds('messenger.message_handler', true) as $serviceId => $tags) {
8065
foreach ($tags as $tag) {
8166
if (isset($tag['bus']) && !\in_array($tag['bus'], $busIds, true)) {
82-
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)));
67+
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)));
8368
}
8469

8570
$className = $this->getServiceClass($container, $serviceId);
@@ -268,7 +253,7 @@ private function registerReceivers(ContainerBuilder $container, array $busIds)
268253
}
269254
}
270255

271-
foreach ($container->findTaggedServiceIds($this->receiverTag) as $id => $tags) {
256+
foreach ($container->findTaggedServiceIds('messenger.receiver') as $id => $tags) {
272257
$receiverClass = $this->getServiceClass($container, $id);
273258
if (!is_subclass_of($receiverClass, ReceiverInterface::class)) {
274259
throw new RuntimeException(sprintf('Invalid receiver "%s": class "%s" must implement interface "%s".', $id, $receiverClass, ReceiverInterface::class));

src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Messenger\Stamp;
1313

14-
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1514
use Symfony\Component\Messenger\Envelope;
1615

1716
/**
@@ -21,23 +20,11 @@ final class RedeliveryStamp implements StampInterface
2120
{
2221
private $retryCount;
2322
private $redeliveredAt;
24-
private $exceptionMessage;
25-
private $flattenException;
2623

27-
public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
24+
public function __construct(int $retryCount, \DateTimeInterface $redeliveredAt = null)
2825
{
2926
$this->retryCount = $retryCount;
3027
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
31-
32-
if (null !== $exceptionMessage) {
33-
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));
34-
}
35-
$this->exceptionMessage = $exceptionMessage;
36-
37-
if (null !== $flattenException) {
38-
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));
39-
}
40-
$this->flattenException = $flattenException;
4128
}
4229

4330
public static function getRetryCountFromEnvelope(Envelope $envelope): int
@@ -53,26 +40,6 @@ public function getRetryCount(): int
5340
return $this->retryCount;
5441
}
5542

56-
/**
57-
* @deprecated since Symfony 5.2, use ErrorDetailsStamp instead.
58-
*/
59-
public function getExceptionMessage(): ?string
60-
{
61-
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));
62-
63-
return $this->exceptionMessage;
64-
}
65-
66-
/**
67-
* @deprecated since Symfony 5.2, use ErrorDetailsStamp instead.
68-
*/
69-
public function getFlattenException(): ?FlattenException
70-
{
71-
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));
72-
73-
return $this->flattenException;
74-
}
75-
7643
public function getRedeliveredAt(): \DateTimeInterface
7744
{
7845
return $this->redeliveredAt;

0 commit comments

Comments
 (0)
0