*/ class InMemoryQueueBroker extends AbstractQueueBroker implements SyncQueueBrokerInterface { /** * @var \SplQueue */ private $queue; /** * @return \SplQueue */ private function getQueue() { if (is_null($this->queue)) { $this->createQueue(); } return $this->queue; } /** * Initiates the SplQueue */ public function createQueue() { $this->queue = new \SplQueue(); $this->logDebug('Memory Queue created'); } /** * @return int */ public function count() { return $this->getQueue()->count(); } /** * @param TaskInterface $task * @return bool */ public function push(TaskInterface $task) { $this->getQueue()->enqueue($this->serializeTask($task)); return true; } /** * Overwriting the parent totally because in this case we need a much simpler logic for popping messages. * * @return mixed|null */ public function pop() { if (!$this->count()) { return null; } $task = $this->getQueue()->dequeue(); return $this->unserializeTask($task, ''); } /** * Do nothing. */ protected function doPop() { } /** * Do nothing, because dequeue automatically deletes the message from the queue * * @param TaskInterface $task */ public function delete(TaskInterface $task) { } /** * Do nothing. * * @param string $receipt * @param array $logContext */ protected function doDelete($receipt, array $logContext = []) { } }