Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 079cb31

Browse files
[Messenger] fix deprecation layer in AbstractFailedMessagesCommand
1 parent f963ae4 commit 079cb31

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
3131
use Symfony\Component\VarDumper\Cloner\Stub;
3232
use Symfony\Component\VarDumper\Cloner\VarCloner;
33+
use Symfony\Contracts\Service\ServiceProviderInterface;
3334

3435
/**
3536
* @author Ryan Weaver <[email protected]>
@@ -38,20 +39,24 @@
3839
*/
3940
abstract class AbstractFailedMessagesCommand extends Command
4041
{
41-
private $globalFailureReceiverName;
4242
protected $failureTransports;
4343

44+
private $globalFailureReceiverName;
45+
46+
/**
47+
* @param ServiceProviderInterface $failureTransports
48+
*/
4449
public function __construct(?string $globalFailureReceiverName, $failureTransports)
4550
{
4651
$this->failureTransports = $failureTransports;
47-
if (!$failureTransports instanceof ServiceLocator) {
48-
trigger_deprecation('symfony/messenger', '5.3', 'Passing a non-scalar value as 2nd argument to "%s()" is deprecated, pass a ServiceLocator instead.', __METHOD__);
52+
if (!$failureTransports instanceof ServiceProviderInterface) {
53+
trigger_deprecation('symfony/messenger', '5.3', 'Passing a receiver as 2nd argument to "%s()" is deprecated, pass a service locator instead.', __METHOD__);
4954

5055
if (null === $globalFailureReceiverName) {
5156
throw new InvalidArgumentException(sprintf('The argument "globalFailureReceiver" from method "%s()" must be not null if 2nd argument is not a ServiceLocator.', __METHOD__));
5257
}
5358

54-
$this->failureTransports = new ServiceLocator([$globalFailureReceiverName => function () use ($failureTransports) { return $failureTransports; },]);
59+
$this->failureTransports = new ServiceLocator([$globalFailureReceiverName => static function () use ($failureTransports) { return $failureTransports; }]);
5560
}
5661
$this->globalFailureReceiverName = $globalFailureReceiverName;
5762

@@ -172,15 +177,22 @@ protected function printPendingMessagesMessage(ReceiverInterface $receiver, Symf
172177
}
173178
}
174179

175-
protected function getReceiver(/* string $name */): ReceiverInterface
180+
/**
181+
* @param string|null $name
182+
*/
183+
protected function getReceiver(/* string $name = null */): ReceiverInterface
176184
{
177-
if (1 > \func_num_args() && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
178-
@trigger_error(sprintf('The "%s()" method will have a new "string $name" argument in version 5.3, not defining it is deprecated since Symfony 5.2.', __METHOD__), \E_USER_DEPRECATED);
185+
if (1 > \func_num_args() && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
186+
trigger_error_deprecation('symfony/messenger', '5.3', 'The "%s()" method will have a new "string $name" argument in version 6.0, not defining it is deprecated.', __METHOD__);
187+
}
188+
$name = \func_num_args() > 0 ? func_get_arg(0) : null;
189+
190+
if (null === $name = $name ?? $this->globalFailureReceiverName) {
191+
throw new InvalidArgumentException(sprintf('No default failure transport is defined. Available transports are: "%s".', $name, implode('", "', array_keys($this->failureTransports->getProvidedServices()))));
179192
}
180193

181-
$name = \func_num_args() > 0 ? func_get_arg(0) : $this->globalFailureReceiverName;
182194
if (!$this->failureTransports->has($name)) {
183-
throw new InvalidArgumentException(sprintf('The failure transport with name "%s" was not found. Available transports are: "%s".', $name, implode(', ', array_keys($this->failureTransports->getProvidedServices()))));
195+
throw new InvalidArgumentException(sprintf('The "%s" failure transport was not found. Available transports are: "%s".', $name, implode('", "', array_keys($this->failureTransports->getProvidedServices()))));
184196
}
185197

186198
return $this->failureTransports->get($name);

0 commit comments

Comments
 (0)