|
30 | 30 | use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
31 | 31 | use Symfony\Component\VarDumper\Cloner\Stub;
|
32 | 32 | use Symfony\Component\VarDumper\Cloner\VarCloner;
|
| 33 | +use Symfony\Contracts\Service\ServiceProviderInterface; |
33 | 34 |
|
34 | 35 | /**
|
35 | 36 | * @author Ryan Weaver <[email protected]>
|
|
38 | 39 | */
|
39 | 40 | abstract class AbstractFailedMessagesCommand extends Command
|
40 | 41 | {
|
41 |
| - private $globalFailureReceiverName; |
42 | 42 | protected $failureTransports;
|
43 | 43 |
|
| 44 | + private $globalFailureReceiverName; |
| 45 | + |
| 46 | + /** |
| 47 | + * @param ServiceProviderInterface $failureTransports |
| 48 | + */ |
44 | 49 | public function __construct(?string $globalFailureReceiverName, $failureTransports)
|
45 | 50 | {
|
46 | 51 | $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__); |
49 | 54 |
|
50 | 55 | if (null === $globalFailureReceiverName) {
|
51 | 56 | throw new InvalidArgumentException(sprintf('The argument "globalFailureReceiver" from method "%s()" must be not null if 2nd argument is not a ServiceLocator.', __METHOD__));
|
52 | 57 | }
|
53 | 58 |
|
54 |
| - $this->failureTransports = new ServiceLocator([$globalFailureReceiverName => function () use ($failureTransports) { return $failureTransports; },]); |
| 59 | + $this->failureTransports = new ServiceLocator([$globalFailureReceiverName => static function () use ($failureTransports) { return $failureTransports; }]); |
55 | 60 | }
|
56 | 61 | $this->globalFailureReceiverName = $globalFailureReceiverName;
|
57 | 62 |
|
@@ -172,15 +177,22 @@ protected function printPendingMessagesMessage(ReceiverInterface $receiver, Symf
|
172 | 177 | }
|
173 | 178 | }
|
174 | 179 |
|
175 |
| - protected function getReceiver(/* string $name */): ReceiverInterface |
| 180 | + /** |
| 181 | + * @param string|null $name |
| 182 | + */ |
| 183 | + protected function getReceiver(/* string $name = null */): ReceiverInterface |
176 | 184 | {
|
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())))); |
179 | 192 | }
|
180 | 193 |
|
181 |
| - $name = \func_num_args() > 0 ? func_get_arg(0) : $this->globalFailureReceiverName; |
182 | 194 | 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())))); |
184 | 196 | }
|
185 | 197 |
|
186 | 198 | return $this->failureTransports->get($name);
|
|
0 commit comments