From e3a4a9e5485f1a43940bc7e4fabc25dd08509077 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 29 Oct 2026 15:30:53 +0800 Subject: [PATCH] refactor: write the Worker commands through `$this->getOutput()` --- system/Commands/Worker/WorkerInstall.php | 45 +++++++++++----------- system/Commands/Worker/WorkerUninstall.php | 28 +++++++------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/system/Commands/Worker/WorkerInstall.php b/system/Commands/Worker/WorkerInstall.php index f64fe2d8ab50..abb02bd2a9db 100644 --- a/system/Commands/Worker/WorkerInstall.php +++ b/system/Commands/Worker/WorkerInstall.php @@ -15,8 +15,8 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\Input\Option; +use CodeIgniter\CLI\Output; /** * Installs the files needed to run CodeIgniter 4 in FrankenPHP worker mode. @@ -49,10 +49,11 @@ protected function configure(): void protected function execute(array $arguments, array $options): int { - $force = $options['force'] === true; + $force = $options['force'] === true; + $output = $this->getOutput(); - CLI::write('Setting up FrankenPHP Worker Mode', 'yellow'); - CLI::newLine(); + $output->write('Setting up FrankenPHP Worker Mode', 'yellow'); + $output->newLine(); helper('filesystem'); @@ -71,52 +72,52 @@ protected function execute(array $arguments, array $options): int $content = file_get_contents($source); if ($content === false) { - CLI::error(sprintf('Failed to read template: %s', $template), 'light_gray', 'red'); + $output->error(sprintf('Failed to read template: %s', $template), 'light_gray', 'red'); return EXIT_ERROR; } if (! write_file($target, $content)) { - CLI::error(sprintf('Failed to create file: %s', clean_path($target)), 'light_gray', 'red'); + $output->error(sprintf('Failed to create file: %s', clean_path($target)), 'light_gray', 'red'); return EXIT_ERROR; } if ($force && $isFile) { - CLI::write(sprintf(' File overwritten: %s', clean_path($target)), 'yellow'); + $output->write(sprintf(' File overwritten: %s', clean_path($target)), 'yellow'); } else { - CLI::write(sprintf(' File created: %s', clean_path($target)), 'green'); + $output->write(sprintf(' File created: %s', clean_path($target)), 'green'); } $created[] = $destination; } if ($created === []) { - CLI::write('Worker mode files already exist.', 'yellow'); - CLI::write('Use --force to overwrite existing files.', 'yellow'); + $output->write('Worker mode files already exist.', 'yellow'); + $output->write('Use --force to overwrite existing files.', 'yellow'); return EXIT_ERROR; } - CLI::newLine(); - CLI::write('Worker mode files created successfully!', 'green'); - CLI::newLine(); + $output->newLine(); + $output->write('Worker mode files created successfully!', 'green'); + $output->newLine(); - $this->showNextSteps(); + $this->showNextSteps($output); return EXIT_SUCCESS; } - private function showNextSteps(): void + private function showNextSteps(Output $output): void { - CLI::write('Next Steps:', 'yellow'); - CLI::newLine(); + $output->write('Next Steps:', 'yellow'); + $output->newLine(); - CLI::write('1. Start FrankenPHP:', 'white'); - CLI::write(' frankenphp run', 'green'); - CLI::newLine(); + $output->write('1. Start FrankenPHP:', 'white'); + $output->write(' frankenphp run', 'green'); + $output->newLine(); - CLI::write('2. Test your application:', 'white'); - CLI::write(' curl http://localhost:8080/', 'green'); + $output->write('2. Test your application:', 'white'); + $output->write(' curl http://localhost:8080/', 'green'); } } diff --git a/system/Commands/Worker/WorkerUninstall.php b/system/Commands/Worker/WorkerUninstall.php index 3e7d8c1111c2..fc0b700ddd57 100644 --- a/system/Commands/Worker/WorkerUninstall.php +++ b/system/Commands/Worker/WorkerUninstall.php @@ -15,7 +15,6 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\Input\Option; /** @@ -57,7 +56,7 @@ protected function interact(array &$arguments, array &$options): void return; } - if (CLI::prompt('Remove the FrankenPHP worker mode files?', ['y', 'n']) === 'y') { + if ($this->getPrompt()->ask('Remove the FrankenPHP worker mode files?', ['y', 'n']) === 'y') { $options['force'] = null; // simulate the presence of the --force option } } @@ -65,33 +64,34 @@ protected function interact(array &$arguments, array &$options): void protected function execute(array $arguments, array $options): int { $existing = $this->existingFiles(); + $output = $this->getOutput(); if ($existing === []) { - CLI::write('No worker mode files found to remove.', 'yellow'); + $output->write('No worker mode files found to remove.', 'yellow'); return EXIT_SUCCESS; } if ($options['force'] === false) { if ($this->isInteractive()) { - CLI::write('Uninstall cancelled.', 'yellow'); + $output->write('Uninstall cancelled.', 'yellow'); return EXIT_SUCCESS; } - CLI::error('Uninstall aborted: pass --force to remove worker mode files in non-interactive mode.', 'light_gray', 'red'); + $output->error('Uninstall aborted: pass --force to remove worker mode files in non-interactive mode.', 'light_gray', 'red'); return EXIT_ERROR; } - CLI::newLine(); - CLI::write('The following files will be removed:', 'yellow'); + $output->newLine(); + $output->write('The following files will be removed:', 'yellow'); foreach ($existing as $file) { - CLI::write(sprintf(' - %s', $file), 'white'); + $output->write(sprintf(' - %s', $file), 'white'); } - CLI::newLine(); + $output->newLine(); $removed = []; @@ -99,25 +99,25 @@ protected function execute(array $arguments, array $options): int $path = ROOTPATH . $file; if (! @unlink($path)) { - CLI::error(sprintf('Failed to remove file: %s', clean_path($path)), 'light_gray', 'red'); + $output->error(sprintf('Failed to remove file: %s', clean_path($path)), 'light_gray', 'red'); continue; } - CLI::write(sprintf(' File removed: %s', clean_path($path)), 'green'); + $output->write(sprintf(' File removed: %s', clean_path($path)), 'green'); $removed[] = $file; } - CLI::newLine(); + $output->newLine(); if ($removed === []) { - CLI::error('No files were removed.', 'light_gray', 'red'); + $output->error('No files were removed.', 'light_gray', 'red'); return EXIT_ERROR; } - CLI::write('Worker mode files removed successfully!', 'green'); + $output->write('Worker mode files removed successfully!', 'green'); return EXIT_SUCCESS; }