From 3e576ce779409b647586c6f47d1cf5ea3adb9e8c Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 13 Aug 2026 20:32:37 +0800 Subject: [PATCH] refactor: migrate `phpini:check` command as modern command --- system/Commands/Utilities/PhpIniCheck.php | 87 ++++++--------------- user_guide_src/source/changelogs/v4.8.0.rst | 1 + 2 files changed, 25 insertions(+), 63 deletions(-) diff --git a/system/Commands/Utilities/PhpIniCheck.php b/system/Commands/Utilities/PhpIniCheck.php index f25518fb283d..c8207df5999e 100644 --- a/system/Commands/Utilities/PhpIniCheck.php +++ b/system/Commands/Utilities/PhpIniCheck.php @@ -13,83 +13,44 @@ namespace CodeIgniter\Commands\Utilities; -use CodeIgniter\CLI\BaseCommand; +use CodeIgniter\CLI\AbstractCommand; +use CodeIgniter\CLI\Attributes\Command; use CodeIgniter\CLI\CLI; +use CodeIgniter\CLI\Input\Argument; use CodeIgniter\Security\CheckPhpIni; /** * Check php.ini values. */ -final class PhpIniCheck extends BaseCommand +#[Command( + name: 'phpini:check', + description: 'Check your php.ini values in production environment.', + group: 'CodeIgniter', +)] +final class PhpIniCheck extends AbstractCommand { - /** - * The group the command is lumped under - * when listing commands. - * - * @var string - */ - protected $group = 'CodeIgniter'; - - /** - * The Command's name - * - * @var string - */ - protected $name = 'phpini:check'; - - /** - * The Command's short description - * - * @var string - */ - protected $description = 'Check your php.ini values in production environment.'; - - /** - * The Command's usage - * - * @var string - */ - protected $usage = 'phpini:check'; - - /** - * The Command's arguments - * - * @var array - */ - protected $arguments = [ - 'opcache' => 'Check detail opcache values in production environment.', - ]; - - /** - * The Command's options - * - * @var array - */ - protected $options = []; - - /** - * @return int - */ - public function run(array $params) + protected function configure(): void { - if (isset($params[0]) && ! in_array($params[0], array_keys($this->arguments), true)) { - CLI::error('You must specify a correct argument.'); - CLI::write(' Usage: ' . $this->usage); - CLI::write(' Example: phpini:check opcache'); - CLI::write('Arguments:'); + $this + ->addArgument(new Argument( + name: 'section', + description: 'The section to check in detail. Only "opcache" is supported.', + default: '', + )) + ->addUsage('phpini:check opcache'); + } - $length = max(array_map(strlen(...), array_keys($this->arguments))); + protected function execute(array $arguments, array $options): int + { + $section = $arguments['section']; - foreach ($this->arguments as $argument => $description) { - CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description); - } + if ($section !== '' && $section !== 'opcache') { + CLI::error('You must specify a correct argument.'); return EXIT_ERROR; } - $argument = $params[0] ?? null; - - CheckPhpIni::run(argument: $argument); + CheckPhpIni::run(argument: $section !== '' ? $section : null); return EXIT_SUCCESS; } diff --git a/user_guide_src/source/changelogs/v4.8.0.rst b/user_guide_src/source/changelogs/v4.8.0.rst index 1327ebdb2be5..4bdd26686dc9 100644 --- a/user_guide_src/source/changelogs/v4.8.0.rst +++ b/user_guide_src/source/changelogs/v4.8.0.rst @@ -37,6 +37,7 @@ Behavior Changes - **Commands:** The ``db:table`` command now returns ``EXIT_SUCCESS`` from ``db:table --show`` (previously ``EXIT_ERROR``), and reports an error instead of prompting when run non-interactively (``--no-interaction`` or piped input) without a valid table. CI/automation that branches on the ``--show`` exit code will need updating. - **Commands:** The ``db:table`` output was reworded: the data and metadata column headers are now capitalized (e.g. ``Id``, ``Created_at``), the connection summary headers read ``Hostname``, ``Database``, ``Username``, ``DB Driver``, ``DB Prefix``, and ``Port``, and the section titles changed (e.g. ``Data of "users" table:``). Scripts that grep the previous output will need updating. - **Commands:** The ``worker:uninstall`` command now returns ``EXIT_SUCCESS`` (previously ``EXIT_ERROR``) when the user declines the interactive confirmation prompt, since user-initiated cancellation is not a failure. In non-interactive mode without ``--force`` it now aborts with ``EXIT_ERROR`` instead of prompting, and the redundant ``Uninstalling FrankenPHP Worker Mode`` header was dropped. Scripts that branch on the previous exit code or wording will need updating. +- **Commands:** The ``phpini:check`` command's invalid-argument error now prints only ``You must specify a correct argument.``. The usage example and the argument listing moved to ``phpini:check --help``, where the argument is now named ``section``. Scripts that grep the previous output will need updating. - **Database:** The Postgre driver's ``$db->error()['code']`` previously always returned ``''``. It now returns the 5-character SQLSTATE string for query and transaction failures (e.g., ``'42P01'``), or ``'08006'`` for connection-level failures. Code that relied on ``$db->error()['code'] === ''`` will need updating. - **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method (e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match.