job = $this->argument("job"); $this->job = str_replace('/', '\\', $this->job); if(! class_exists($this->job)) { $this->job = str_ireplace(["App", "Jobs"], "", $this->job); $this->job = trim($this->job, "\\"); $this->job = "App\\Jobs\\{$this->job}"; if(! class_exists($this->job)) { throw new InvalidArgumentException("{$this->job} class does not exist."); } } $this->params = null; $class = new ReflectionClass($this->job); $constructor = $class->getConstructor(); if(! empty($constructor) && ! empty($constructor->getParameters())) { $this->params = $this->option("params") ?? null; if(! empty($this->params) && method_exists($this->job, "formatParameters")) { $this->params = $this->job::formatParameters(... $this->params); } } if($this->option('sync')) { $this->job::dispatchSync(... $this->params); return 0; } $this->queue = $this->option("queue"); $this->connection = $this->option("connection"); if(! in_array($this->connection, ["sync", "database"])) { $this->connection = "database"; } $this->delay = 0; $date = $this->option("date"); if($date != "now") { $format = "Y-m-d H:i:s"; $d = DateTime::createFromFormat($format, $date); if($d && $d->format($format) === $date) { if (strtotime($date) > strtotime('now')) { $this->delay = now()->addSeconds(strtotime($date) - strtotime('now')); } } } $this->job::dispatch(... $this->params) ->onConnection($this->connection) ->onQueue($this->queue) ->delay($this->delay); $this->line("Job has been scheduled."); return 0; } catch (Exception $e) { $this->line($e->getMessage() . " on line " . $e->getLine()); } } }