input = $input; $this->output = $output; return $this->handle(); } abstract protected function handle(): int; protected function write(string $message, bool $newline = true): void { $this->output->write($message, $newline); } protected function info(string $message, bool $newline = true): void { $this->write("{$message}", $newline); } protected function error(string $message, bool $newline = true): void { $this->write("{$message}", $newline); } protected function comment(string $message, bool $newline = true): void { $this->write("{$message}", $newline); } protected function question(string $message, bool $newline = true): void { $this->write("{$message}", $newline); } protected function detail(string $message, bool $newline = true): void { $this->write("{$message}", $newline); } protected function section(string $message, callable $callback): void { $output = $this->output; if (!$output instanceof ConsoleOutputInterface) { throw new \LogicException('Section 功能只能在 ConsoleOutputInterface 中使用'); } $this->info($message); $section = $output->section(); try { $callback($section); } catch (ZMException $e) { $this->error($e->getMessage()); exit(1); } } }