16
16
use Psr \Log \LoggerInterface ;
17
17
use Psr \Log \NullLogger ;
18
18
19
- class QueueConsumer
19
+ final class QueueConsumer implements QueueConsumerInterface
20
20
{
21
21
/**
22
22
* @var PsrContext
@@ -71,8 +71,8 @@ class QueueConsumer
71
71
public function __construct (
72
72
PsrContext $ psrContext ,
73
73
ExtensionInterface $ extension = null ,
74
- $ idleTimeout = 0 ,
75
- $ receiveTimeout = 10000
74
+ float $ idleTimeout = 0. ,
75
+ float $ receiveTimeout = 10000.
76
76
) {
77
77
$ this ->psrContext = $ psrContext ;
78
78
$ this ->staticExtension = $ extension ?: new ChainExtension ([]);
@@ -85,62 +85,55 @@ public function __construct(
85
85
}
86
86
87
87
/**
88
- * @param int $timeout
88
+ * {@inheritdoc}
89
89
*/
90
- public function setIdleTimeout ($ timeout )
90
+ public function setIdleTimeout (float $ timeout ): void
91
91
{
92
- $ this ->idleTimeout = ( int ) $ timeout ;
92
+ $ this ->idleTimeout = $ timeout ;
93
93
}
94
94
95
95
/**
96
- * @return int
96
+ * {@inheritdoc}
97
97
*/
98
- public function getIdleTimeout ()
98
+ public function getIdleTimeout (): float
99
99
{
100
100
return $ this ->idleTimeout ;
101
101
}
102
102
103
103
/**
104
- * @param int $timeout
104
+ * {@inheritdoc}
105
105
*/
106
- public function setReceiveTimeout ($ timeout )
106
+ public function setReceiveTimeout (float $ timeout ): void
107
107
{
108
- $ this ->receiveTimeout = ( int ) $ timeout ;
108
+ $ this ->receiveTimeout = $ timeout ;
109
109
}
110
110
111
111
/**
112
- * @return int
112
+ * {@inheritdoc}
113
113
*/
114
- public function getReceiveTimeout ()
114
+ public function getReceiveTimeout (): float
115
115
{
116
116
return $ this ->receiveTimeout ;
117
117
}
118
118
119
119
/**
120
- * @return PsrContext
120
+ * {@inheritdoc}
121
121
*/
122
- public function getPsrContext ()
122
+ public function getPsrContext (): PsrContext
123
123
{
124
124
return $ this ->psrContext ;
125
125
}
126
126
127
127
/**
128
- * @param PsrQueue|string $queue
129
- * @param PsrProcessor|callable $processor
130
- *
131
- * @return QueueConsumer
128
+ * {@inheritdoc}
132
129
*/
133
- public function bind ($ queue , $ processor )
130
+ public function bind ($ queue , PsrProcessor $ processor ): QueueConsumerInterface
134
131
{
135
132
if (is_string ($ queue )) {
136
133
$ queue = $ this ->psrContext ->createQueue ($ queue );
137
134
}
138
- if (is_callable ($ processor )) {
139
- $ processor = new CallbackProcessor ($ processor );
140
- }
141
135
142
136
InvalidArgumentException::assertInstanceOf ($ queue , PsrQueue::class);
143
- InvalidArgumentException::assertInstanceOf ($ processor , PsrProcessor::class);
144
137
145
138
if (empty ($ queue ->getQueueName ())) {
146
139
throw new LogicException ('The queue name must be not empty. ' );
@@ -155,14 +148,17 @@ public function bind($queue, $processor)
155
148
}
156
149
157
150
/**
158
- * Runtime extension - is an extension or a collection of extensions which could be set on runtime.
159
- * Here's a good example: @see LimitsExtensionsCommandTrait.
160
- *
161
- * @param ExtensionInterface|ChainExtension|null $runtimeExtension
162
- *
163
- * @throws \Exception
151
+ * {@inheritdoc}
152
+ */
153
+ public function bindCallback ($ queue , callable $ processor ): QueueConsumerInterface
154
+ {
155
+ return $ this ->bind ($ queue , new CallbackProcessor ($ processor ));
156
+ }
157
+
158
+ /**
159
+ * {@inheritdoc}
164
160
*/
165
- public function consume (ExtensionInterface $ runtimeExtension = null )
161
+ public function consume (ExtensionInterface $ runtimeExtension = null ): void
166
162
{
167
163
if (empty ($ this ->boundProcessors )) {
168
164
throw new \LogicException ('There is nothing to consume. It is required to bind something before calling consume method. ' );
0 commit comments