connection = $connection; $this->serializer = $serializer ?? new PhpSerializer(); } /** * {@inheritdoc} */ public function get(): iterable { $pheanstalkEnvelope = $this->connection->get(); if (null === $pheanstalkEnvelope) { return []; } $message = $this->connection->deserializeJob($pheanstalkEnvelope->getData()); try { $envelope = $this->serializer->decode([ 'body' => $message['body'], 'headers' => $message['headers'] ]); } catch (MessageDecodingFailedException $exception) { $this->connection->getClient()->delete($pheanstalkEnvelope); throw $exception; } return [$envelope->with(new BeanstalkReceivedStamp($this->connection->getTube(), $pheanstalkEnvelope))]; } /** * {@inheritdoc} */ public function ack(Envelope $envelope): void { $this->connection->ack($this->findReceivedStamp($envelope)->getJob()); } /** * {@inheritdoc} */ public function reject(Envelope $envelope): void { $this->connection->reject($this->findReceivedStamp($envelope)->getJob()); } private function findReceivedStamp(Envelope $envelope): BeanstalkReceivedStamp { /** @var BeanstalkReceivedStamp|null $receivedStamp */ $receivedStamp = $envelope->last(BeanstalkReceivedStamp::class); if (null === $receivedStamp) { throw new LogicException('No BeanstalkReceivedStamp found on the Envelope.'); } return $receivedStamp; } }