44
55namespace Yiisoft \Queue \Adapter ;
66
7+ use BackedEnum ;
78use InvalidArgumentException ;
9+ use Yiisoft \Queue \ChannelNormalizer ;
810use Yiisoft \Queue \Enum \JobStatus ;
911use Yiisoft \Queue \Message \MessageInterface ;
1012use Yiisoft \Queue \QueueInterface ;
@@ -15,12 +17,14 @@ final class SynchronousAdapter implements AdapterInterface
1517{
1618 private array $ messages = [];
1719 private int $ current = 0 ;
20+ private string $ channel ;
1821
1922 public function __construct (
2023 private WorkerInterface $ worker ,
2124 private QueueInterface $ queue ,
22- private string $ channel = QueueInterface::DEFAULT_CHANNEL_NAME ,
25+ string | BackedEnum $ channel = QueueInterface::DEFAULT_CHANNEL_NAME ,
2326 ) {
27+ $ this ->channel = ChannelNormalizer::normalize ($ channel );
2428 }
2529
2630 public function __destruct ()
@@ -74,8 +78,10 @@ public function subscribe(callable $handlerCallback): void
7478 $ this ->runExisting ($ handlerCallback );
7579 }
7680
77- public function withChannel (string $ channel ): self
81+ public function withChannel (string | BackedEnum $ channel ): self
7882 {
83+ $ channel = ChannelNormalizer::normalize ($ channel );
84+
7985 if ($ channel === $ this ->channel ) {
8086 return $ this ;
8187 }
0 commit comments