queue = $queue; $this->queue_map = $queue_map; } /** * @inheritdoc */ public function execute($command, callable $next) { if ($command instanceof QueueableCommand) { $queue = $this->getQueue(get_class($command)); return $this->queue->add( $queue, // Wraps the command so it isn't requeued new QueuedCommand($command) ); } if ($command instanceof QueuedCommand) { $command = $command->command(); } return $next($command); } /** * Gets the specific queue for the command * * @param string $command_name * * @return string * * @throws \Exception If the command isn't assigned to a pipe */ private function getQueue($command_name) { foreach ($this->queue_map as $queue => $commands) { if (in_array($command_name, $commands)) { return $queue; } } throw new Exception( sprintf('No queue has been set for the `%s` command', $command_name) ); } }