thomasvargiu /
laminas-messenger
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace TMV\Laminas\Messenger\Factory\Middleware; |
||
| 6 | |||
| 7 | use Psr\Container\ContainerInterface; |
||
| 8 | use Symfony\Component\Messenger\Middleware\AddBusNameStampMiddleware; |
||
| 9 | use Symfony\Component\Messenger\Middleware\MiddlewareInterface; |
||
| 10 | use TMV\Laminas\Messenger\Exception\InvalidArgumentException; |
||
| 11 | |||
| 12 | use function array_key_exists; |
||
| 13 | use function sprintf; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @psalm-api |
||
| 17 | */ |
||
| 18 | 1 | final class AddBusNameStampMiddlewareFactory |
|
| 19 | { |
||
| 20 | 1 | private string $busName; |
|
| 21 | 1 | ||
| 22 | public function __construct(string $busName = 'messenger.bus.default') |
||
| 23 | 1 | { |
|
| 24 | $this->busName = $busName; |
||
| 25 | 1 | } |
|
| 26 | |||
| 27 | public function __invoke(ContainerInterface $container): AddBusNameStampMiddleware |
||
| 28 | { |
||
| 29 | return new AddBusNameStampMiddleware($this->busName); |
||
| 30 | } |
||
| 31 | |||
| 32 | public static function __set_state(array $data): self |
||
| 33 | { |
||
| 34 | 2 | return new self($data['busName'] ?? null); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | } |
||
| 36 | 2 | ||
| 37 | 1 | /** |
|
| 38 | 1 | * @psalm-api |
|
| 39 | 1 | * |
|
| 40 | * @param array<int, mixed> $arguments |
||
| 41 | */ |
||
| 42 | public static function __callStatic(string $name, array $arguments): MiddlewareInterface |
||
| 43 | 1 | { |
|
| 44 | if (! array_key_exists(0, $arguments) || ! $arguments[0] instanceof ContainerInterface) { |
||
| 45 | throw new InvalidArgumentException(sprintf( |
||
| 46 | 'The first argument must be of type %s', |
||
| 47 | ContainerInterface::class |
||
| 48 | )); |
||
| 49 | } |
||
| 50 | |||
| 51 | return (new self($name))($arguments[0]); |
||
| 52 | } |
||
| 53 | } |
||
| 54 |