1 | <?php |
||
18 | class QueueWorker implements \SplSubject |
||
19 | { |
||
20 | |||
21 | const STATE_REQUEST = 1; |
||
22 | const STATE_RESPONSE = 2; |
||
23 | |||
24 | /** |
||
25 | * @var PsrContext |
||
26 | */ |
||
27 | private $context; |
||
28 | |||
29 | /** |
||
30 | * @var PsrQueue |
||
31 | */ |
||
32 | private $queue; |
||
33 | |||
34 | /** |
||
35 | * @var ClientInterface |
||
36 | */ |
||
37 | private $guzzle; |
||
38 | |||
39 | /** |
||
40 | * @var float |
||
41 | */ |
||
42 | private $timeout; |
||
43 | |||
44 | /** |
||
45 | * @var \SplObserver[] |
||
46 | */ |
||
47 | private $observers = []; |
||
48 | |||
49 | /** |
||
50 | * @var RequestInterface |
||
51 | */ |
||
52 | private $currentRequest; |
||
53 | |||
54 | /** |
||
55 | * @var ResponseInterface |
||
56 | */ |
||
57 | private $lastResponse; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | */ |
||
62 | private $state; |
||
63 | |||
64 | /** |
||
65 | * EnqueuePromisor constructor. |
||
66 | * @param PsrContext $context |
||
67 | * @param string $queueName |
||
68 | * @param ClientInterface $guzzle |
||
69 | * @param float $timeout |
||
70 | * @throws \InvalidArgumentException |
||
71 | */ |
||
72 | public function __construct(PsrContext $context, ClientInterface $guzzle, $queueName = '', $timeout = 0.0) |
||
82 | |||
83 | /** |
||
84 | * @param PsrConnectionFactory $factory |
||
85 | * @param string $queueName |
||
86 | * @param ClientInterface $guzzle |
||
87 | * @param float $timeout |
||
88 | * @return QueueWorker |
||
89 | */ |
||
90 | public static function factory(PsrConnectionFactory $factory, ClientInterface $guzzle, $queueName = '', $timeout = 0.0) |
||
94 | |||
95 | /** |
||
96 | * @param null $maxRequests |
||
97 | * @param \DateTimeImmutable|null $endAt |
||
98 | */ |
||
99 | public function loop($maxRequests = null, \DateTimeImmutable $endAt = null) |
||
132 | |||
133 | /** |
||
134 | * @return RequestInterface |
||
135 | */ |
||
136 | public function getCurrentRequest() |
||
140 | |||
141 | /** |
||
142 | * @return ResponseInterface |
||
143 | */ |
||
144 | public function getLastResponse() |
||
148 | |||
149 | /** |
||
150 | * @return int |
||
151 | */ |
||
152 | public function getState() |
||
156 | |||
157 | /** |
||
158 | * @param PsrMessage $message |
||
159 | * @param PsrConsumer $consumer |
||
160 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
161 | */ |
||
162 | private function process(PsrMessage $message, PsrConsumer $consumer) |
||
212 | |||
213 | /** |
||
214 | * @param PsrMessage $message |
||
215 | * @return array |
||
216 | */ |
||
217 | private function unwrap(PsrMessage $message) |
||
222 | |||
223 | /** |
||
224 | * @inheritDoc |
||
225 | */ |
||
226 | public function attach(SplObserver $observer) |
||
230 | |||
231 | /** |
||
232 | * @inheritDoc |
||
233 | */ |
||
234 | public function detach(SplObserver $observer) |
||
242 | |||
243 | /** |
||
244 | * @inheritDoc |
||
245 | */ |
||
246 | public function notify() |
||
254 | } |
||
255 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: