Skip to content

Commit 5a4edad

Browse files
authored
Remove QueueInterface::withAdapter() and AdapterFactoryQueueProvider (#266)
1 parent 5999193 commit 5a4edad

23 files changed

Lines changed: 61 additions & 569 deletions

config/di.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,12 @@
1717
use Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPush;
1818
use Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPushInterface;
1919
use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher;
20-
use Yiisoft\Queue\Provider\AdapterFactoryQueueProvider;
21-
use Yiisoft\Queue\Provider\QueueProviderInterface;
22-
use Yiisoft\Queue\Queue;
23-
use Yiisoft\Queue\QueueInterface;
2420
use Yiisoft\Queue\Worker\Worker as QueueWorker;
2521
use Yiisoft\Queue\Worker\WorkerInterface;
2622

2723
/* @var array $params */
2824

2925
return [
30-
AdapterFactoryQueueProvider::class => [
31-
'__construct()' => [
32-
'definitions' => $params['yiisoft/queue']['queues'],
33-
],
34-
],
35-
QueueProviderInterface::class => AdapterFactoryQueueProvider::class,
3626
QueueWorker::class => [
3727
'class' => QueueWorker::class,
3828
'__construct()' => [$params['yiisoft/queue']['handlers']],
@@ -43,7 +33,6 @@
4333
? $container->get(SignalLoop::class)
4434
: $container->get(SimpleLoop::class);
4535
},
46-
QueueInterface::class => Queue::class,
4736
MiddlewareFactoryPushInterface::class => MiddlewareFactoryPush::class,
4837
MiddlewareFactoryConsumeInterface::class => MiddlewareFactoryConsume::class,
4938
MiddlewareFactoryFailureInterface::class => MiddlewareFactoryFailure::class,

config/params.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use Yiisoft\Queue\Adapter\AdapterInterface;
65
use Yiisoft\Queue\Command\ListenAllCommand;
76
use Yiisoft\Queue\Command\ListenCommand;
87
use Yiisoft\Queue\Command\RunCommand;
@@ -22,9 +21,6 @@
2221
],
2322
'yiisoft/queue' => [
2423
'handlers' => [],
25-
'queues' => [
26-
QueueProviderInterface::DEFAULT_QUEUE => AdapterInterface::class,
27-
],
2824
'middlewares-push' => [],
2925
'middlewares-consume' => [],
3026
'middlewares-fail' => [],

src/Debug/QueueDecorator.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Yiisoft\Queue\Debug;
66

7-
use BackedEnum;
8-
use Yiisoft\Queue\Adapter\AdapterInterface;
97
use Yiisoft\Queue\JobStatus;
108
use Yiisoft\Queue\Message\MessageInterface;
119
use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface;
@@ -45,11 +43,6 @@ public function listen(): void
4543
$this->queue->listen();
4644
}
4745

48-
public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static
49-
{
50-
return new self($this->queue->withAdapter($adapter, $queueName), $this->collector);
51-
}
52-
5346
public function getName(): string
5447
{
5548
return $this->queue->getName();

src/Exception/AdapterConfiguration/AdapterNotConfiguredException.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Middleware/Push/AdapterPushHandler.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44

55
namespace Yiisoft\Queue\Middleware\Push;
66

7-
use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException;
8-
97
/**
108
* @internal
119
*/
1210
final class AdapterPushHandler implements MessageHandlerPushInterface
1311
{
1412
public function handlePush(PushRequest $request): PushRequest
1513
{
16-
if (($adapter = $request->getAdapter()) === null) {
17-
throw new AdapterNotConfiguredException();
18-
}
19-
return $request->withMessage($adapter->push($request->getMessage()));
14+
return $request->withMessage(
15+
$request->getAdapter()->push(
16+
$request->getMessage(),
17+
),
18+
);
2019
}
2120
}

src/Middleware/Push/PushRequest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
final class PushRequest
1111
{
12-
public function __construct(private MessageInterface $message, private ?AdapterInterface $adapter) {}
12+
public function __construct(
13+
private MessageInterface $message,
14+
private AdapterInterface $adapter,
15+
) {}
1316

1417
public function getMessage(): MessageInterface
1518
{
1619
return $this->message;
1720
}
1821

19-
public function getAdapter(): ?AdapterInterface
22+
public function getAdapter(): AdapterInterface
2023
{
2124
return $this->adapter;
2225
}

src/Provider/AdapterFactoryQueueProvider.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/Queue.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Psr\Log\LoggerInterface;
99
use Yiisoft\Queue\Adapter\AdapterInterface;
1010
use Yiisoft\Queue\Cli\LoopInterface;
11-
use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException;
1211
use Yiisoft\Queue\Message\MessageInterface;
1312
use Yiisoft\Queue\Middleware\Push\AdapterPushHandler;
1413
use Yiisoft\Queue\Middleware\Push\MessageHandlerPushInterface;
@@ -29,12 +28,12 @@ final class Queue implements QueueInterface
2928
private string $name;
3029

3130
public function __construct(
31+
private readonly AdapterInterface $adapter,
3232
private readonly WorkerInterface $worker,
3333
private readonly LoopInterface $loop,
3434
private readonly LoggerInterface $logger,
3535
private readonly PushMiddlewareDispatcher $pushMiddlewareDispatcher,
3636
string|BackedEnum $name = QueueProviderInterface::DEFAULT_QUEUE,
37-
private ?AdapterInterface $adapter = null,
3837
MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions,
3938
) {
4039
$this->name = StringNormalizer::normalize($name);
@@ -51,7 +50,6 @@ public function push(
5150
MessageInterface $message,
5251
MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions,
5352
): MessageInterface {
54-
$this->checkAdapter();
5553
$this->logger->debug(
5654
'Preparing to push message with handler name "{handlerName}".',
5755
['handlerName' => $message->getHandlerName()],
@@ -74,8 +72,6 @@ public function push(
7472

7573
public function run(int $max = 0): int
7674
{
77-
$this->checkAdapter();
78-
7975
$this->logger->debug('Start processing queue messages.');
8076
$count = 0;
8177

@@ -100,30 +96,16 @@ public function run(int $max = 0): int
10096

10197
public function listen(): void
10298
{
103-
$this->checkAdapter();
104-
10599
$this->logger->info('Start listening to the queue.');
106100
$this->adapter->subscribe(fn(MessageInterface $message) => $this->handle($message));
107101
$this->logger->info('Finish listening to the queue.');
108102
}
109103

110104
public function status(string|int $id): JobStatus
111105
{
112-
$this->checkAdapter();
113106
return $this->adapter->status($id);
114107
}
115108

116-
public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static
117-
{
118-
$new = clone $this;
119-
$new->adapter = $adapter;
120-
if ($queueName !== null) {
121-
$new->name = StringNormalizer::normalize($queueName);
122-
}
123-
124-
return $new;
125-
}
126-
127109
public function withMiddlewares(MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions): self
128110
{
129111
$instance = clone $this;
@@ -147,16 +129,6 @@ private function handle(MessageInterface $message): bool
147129
return $this->loop->canContinue();
148130
}
149131

150-
/**
151-
* @psalm-assert AdapterInterface $this->adapter
152-
*/
153-
private function checkAdapter(): void
154-
{
155-
if ($this->adapter === null) {
156-
throw new AdapterNotConfiguredException();
157-
}
158-
}
159-
160132
private function createPushHandler(MiddlewarePushInterface|callable|array|string ...$middlewares): MessageHandlerPushInterface
161133
{
162134
return new class (

src/QueueInterface.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace Yiisoft\Queue;
66

7-
use BackedEnum;
87
use InvalidArgumentException;
9-
use Yiisoft\Queue\Adapter\AdapterInterface;
108
use Yiisoft\Queue\Message\MessageInterface;
119
use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface;
1210

@@ -41,14 +39,6 @@ public function listen(): void;
4139
*/
4240
public function status(string|int $id): JobStatus;
4341

44-
/**
45-
* @param AdapterInterface $adapter Adapter to use.
46-
* @param string|BackedEnum|null $queueName Queue name to use.
47-
*
48-
* @return static A new queue with the given adapter and queue name.
49-
*/
50-
public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static;
51-
5242
/**
5343
* Returns the logical name of the queue.
5444
*/

0 commit comments

Comments
 (0)