Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions system/Commands/Worker/WorkerInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');

Expand All @@ -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');
}
}
28 changes: 14 additions & 14 deletions system/Commands/Worker/WorkerUninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Option;

/**
Expand Down Expand Up @@ -57,67 +56,68 @@ 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
}
}

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 = [];

foreach ($existing as $file) {
$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;
}
Expand Down
Loading