Skip to content

Commit 5c0923d

Browse files
committed
Migrate gearman transport
1 parent 45895d5 commit 5c0923d

9 files changed

Lines changed: 90 additions & 274 deletions

‎pkg/gearman/GearmanConnectionFactory.php‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Enqueue\Gearman;
44

55
use Interop\Queue\PsrConnectionFactory;
6+
use Interop\Queue\PsrContext;
67

78
class GearmanConnectionFactory implements PsrConnectionFactory
89
{
@@ -40,21 +41,14 @@ public function __construct($config = 'gearman:')
4041
}
4142

4243
/**
43-
* {@inheritdoc}
44-
*
4544
* @return GearmanContext
4645
*/
47-
public function createContext()
46+
public function createContext(): PsrContext
4847
{
4948
return new GearmanContext($this->config);
5049
}
5150

52-
/**
53-
* @param string $dsn
54-
*
55-
* @return array
56-
*/
57-
private function parseDsn($dsn)
51+
private function parseDsn(string $dsn): array
5852
{
5953
$dsnConfig = parse_url($dsn);
6054
if (false === $dsnConfig) {
@@ -81,10 +75,7 @@ private function parseDsn($dsn)
8175
];
8276
}
8377

84-
/**
85-
* @return array
86-
*/
87-
private function defaultConfig()
78+
private function defaultConfig(): array
8879
{
8980
return [
9081
'host' => \GEARMAN_DEFAULT_TCP_HOST,

‎pkg/gearman/GearmanConsumer.php‎

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

55
use Interop\Queue\PsrConsumer;
66
use Interop\Queue\PsrMessage;
7+
use Interop\Queue\PsrQueue;
78

89
class GearmanConsumer implements PsrConsumer
910
{
@@ -22,12 +23,6 @@ class GearmanConsumer implements PsrConsumer
2223
*/
2324
private $context;
2425

25-
/**
26-
* @param GearmanContext $context
27-
* @param GearmanDestination $destination
28-
*
29-
* @internal param \GearmanWorker $worker
30-
*/
3126
public function __construct(GearmanContext $context, GearmanDestination $destination)
3227
{
3328
$this->context = $context;
@@ -37,21 +32,17 @@ public function __construct(GearmanContext $context, GearmanDestination $destina
3732
}
3833

3934
/**
40-
* {@inheritdoc}
41-
*
4235
* @return GearmanDestination
4336
*/
44-
public function getQueue()
37+
public function getQueue(): PsrQueue
4538
{
4639
return $this->destination;
4740
}
4841

4942
/**
50-
* {@inheritdoc}
51-
*
5243
* @return GearmanMessage
5344
*/
54-
public function receive($timeout = 0)
45+
public function receive(int $timeout = 0): ?PsrMessage
5546
{
5647
set_error_handler(function ($severity, $message, $file, $line) {
5748
throw new \ErrorException($message, 0, $severity, $file, $line);
@@ -75,34 +66,31 @@ public function receive($timeout = 0)
7566
}
7667

7768
/**
78-
* {@inheritdoc}
69+
* @return GearmanMessage
7970
*/
80-
public function receiveNoWait()
71+
public function receiveNoWait(): ?PsrMessage
8172
{
8273
return $this->receive(100);
8374
}
8475

8576
/**
86-
* {@inheritdoc}
77+
* @param GearmanMessage $message
8778
*/
88-
public function acknowledge(PsrMessage $message)
79+
public function acknowledge(PsrMessage $message): void
8980
{
9081
}
9182

9283
/**
93-
* {@inheritdoc}
84+
* @param GearmanMessage $message
9485
*/
95-
public function reject(PsrMessage $message, $requeue = false)
86+
public function reject(PsrMessage $message, bool $requeue = false): void
9687
{
9788
if ($requeue) {
9889
$this->context->createProducer()->send($this->destination, $message);
9990
}
10091
}
10192

102-
/**
103-
* @return \GearmanWorker
104-
*/
105-
public function getWorker()
93+
public function getWorker(): \GearmanWorker
10694
{
10795
return $this->worker;
10896
}

‎pkg/gearman/GearmanContext.php‎

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
namespace Enqueue\Gearman;
44

55
use Interop\Queue\InvalidDestinationException;
6+
use Interop\Queue\PsrConsumer;
67
use Interop\Queue\PsrContext;
78
use Interop\Queue\PsrDestination;
9+
use Interop\Queue\PsrMessage;
10+
use Interop\Queue\PsrProducer;
11+
use Interop\Queue\PsrQueue;
12+
use Interop\Queue\PsrSubscriptionConsumer;
13+
use Interop\Queue\PsrTopic;
14+
use Interop\Queue\PurgeQueueNotSupportedException;
15+
use Interop\Queue\SubscriptionConsumerNotSupportedException;
16+
use Interop\Queue\TemporaryQueueNotSupportedException;
817

918
class GearmanContext implements PsrContext
1019
{
@@ -23,68 +32,54 @@ class GearmanContext implements PsrContext
2332
*/
2433
private $config;
2534

26-
/**
27-
* @param array $config
28-
*/
2935
public function __construct(array $config)
3036
{
3137
$this->config = $config;
3238
}
3339

3440
/**
35-
* {@inheritdoc}
36-
*
3741
* @return GearmanMessage
3842
*/
39-
public function createMessage($body = '', array $properties = [], array $headers = [])
43+
public function createMessage(string $body = '', array $properties = [], array $headers = []): PsrMessage
4044
{
4145
return new GearmanMessage($body, $properties, $headers);
4246
}
4347

4448
/**
45-
* {@inheritdoc}
46-
*
4749
* @return GearmanDestination
4850
*/
49-
public function createTopic($topicName)
51+
public function createTopic(string $topicName): PsrTopic
5052
{
5153
return new GearmanDestination($topicName);
5254
}
5355

5456
/**
55-
* {@inheritdoc}
57+
* @return GearmanDestination
5658
*/
57-
public function createQueue($queueName)
59+
public function createQueue(string $queueName): PsrQueue
5860
{
5961
return new GearmanDestination($queueName);
6062
}
6163

62-
/**
63-
* {@inheritdoc}
64-
*/
65-
public function createTemporaryQueue()
64+
public function createTemporaryQueue(): PsrQueue
6665
{
67-
throw new \LogicException('Not implemented');
66+
throw TemporaryQueueNotSupportedException::providerDoestNotSupportIt();
6867
}
6968

7069
/**
71-
* {@inheritdoc}
72-
*
7370
* @return GearmanProducer
7471
*/
75-
public function createProducer()
72+
public function createProducer(): PsrProducer
7673
{
7774
return new GearmanProducer($this->getClient());
7875
}
7976

8077
/**
81-
* {@inheritdoc}
82-
*
8378
* @param GearmanDestination $destination
8479
*
8580
* @return GearmanConsumer
8681
*/
87-
public function createConsumer(PsrDestination $destination)
82+
public function createConsumer(PsrDestination $destination): PsrConsumer
8883
{
8984
InvalidDestinationException::assertDestinationInstanceOf($destination, GearmanDestination::class);
9085

@@ -93,7 +88,7 @@ public function createConsumer(PsrDestination $destination)
9388
return $consumer;
9489
}
9590

96-
public function close()
91+
public function close(): void
9792
{
9893
$this->getClient()->clearCallbacks();
9994

@@ -102,10 +97,17 @@ public function close()
10297
}
10398
}
10499

105-
/**
106-
* @return \GearmanClient
107-
*/
108-
public function getClient()
100+
public function createSubscriptionConsumer(): PsrSubscriptionConsumer
101+
{
102+
throw SubscriptionConsumerNotSupportedException::providerDoestNotSupportIt();
103+
}
104+
105+
public function purgeQueue(PsrQueue $queue): void
106+
{
107+
throw PurgeQueueNotSupportedException::providerDoestNotSupportIt();
108+
}
109+
110+
public function getClient(): \GearmanClient
109111
{
110112
if (false == $this->client) {
111113
$this->client = new \GearmanClient();
@@ -115,10 +117,7 @@ public function getClient()
115117
return $this->client;
116118
}
117119

118-
/**
119-
* @return \GearmanWorker
120-
*/
121-
public function createWorker()
120+
public function createWorker(): \GearmanWorker
122121
{
123122
$worker = new \GearmanWorker();
124123
$worker->addServer($this->config['host'], $this->config['port']);

‎pkg/gearman/GearmanDestination.php‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,23 @@ class GearmanDestination implements PsrQueue, PsrTopic
1212
*/
1313
private $destinationName;
1414

15-
/**
16-
* @param string $destinationName
17-
*/
18-
public function __construct($destinationName)
15+
public function __construct(string $destinationName)
1916
{
2017
$this->destinationName = $destinationName;
2118
}
2219

23-
/**
24-
* @return string
25-
*/
26-
public function getName()
20+
public function getName(): string
2721
{
2822
return $this->destinationName;
2923
}
3024

31-
/**
32-
* {@inheritdoc}
33-
*/
34-
public function getQueueName()
25+
public function getQueueName(): string
3526
{
36-
return $this->getName();
27+
return $this->destinationName;
3728
}
3829

39-
/**
40-
* {@inheritdoc}
41-
*/
42-
public function getTopicName()
30+
public function getTopicName(): string
4331
{
44-
return $this->getName();
32+
return $this->destinationName;
4533
}
4634
}

0 commit comments

Comments
 (0)