ignoreValidationErrors(); } /** * Execute the console command. */ public function handle() { // Get command arguments $service = $this->argument('service'); $task = $this->argument('task'); $debug_mode = $this->option('debug'); // Parse all remaining options as task parameters // We need to manually parse from $_SERVER['argv'] because Laravel validates options $params = []; $skip_builtins = ['help', 'quiet', 'verbose', 'version', 'ansi', 'no-ansi', 'no-interaction', 'env', 'debug']; // Parse from raw argv $argv = $_SERVER['argv'] ?? []; for ($i = 0; $i < count($argv); $i++) { $arg = $argv[$i]; // Check if this is an option if (!str_starts_with($arg, '--')) { continue; } // Remove -- prefix $option_string = substr($arg, 2); // Parse key=value or just key if (str_contains($option_string, '=')) { [$key, $value] = explode('=', $option_string, 2); } else { $key = $option_string; $value = true; // Boolean flag } // Skip built-in Laravel options if (in_array($key, $skip_builtins)) { continue; } // Try to parse JSON values if (is_string($value) && (str_starts_with($value, '{') || str_starts_with($value, '['))) { $decoded = json_decode($value, true); if (json_last_error() === JSON_ERROR_NONE) { $value = $decoded; } } // Store parameter $params[$key] = $value; } try { // Execute the task $response = Task::internal($service, $task, $params); // Output response based on mode if ($debug_mode) { $wrapped_response = Task::format_task_response($response); $this->output_json($wrapped_response); } else { // Just output the raw response $this->output_json($response); } } catch (\Exception $e) { $this->output_json_error($e->getMessage(), get_class($e), [ 'trace' => $e->getTraceAsString() ]); return 1; } return 0; } /** * Output JSON to stdout (pretty-printed) */ protected function output_json($data): void { $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); $this->line($json); } /** * Output error as JSON */ protected function output_json_error(string $message, string $error_type, array $extra = []): void { $error = [ 'success' => false, 'error' => $message, 'error_type' => $error_type, ]; foreach ($extra as $key => $value) { $error[$key] = $value; } $this->output_json($error); } }