From 568b28c165fb3d1e6102448e10e662b8691a8090 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Wed, 11 Feb 2026 09:18:46 +0000 Subject: Ensure CLI commands only run from the CLI --- app/Cli/Commands/AbstractCommand.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Cli/Commands/AbstractCommand.php b/app/Cli/Commands/AbstractCommand.php index 7e5b301b85..c175fb05fa 100644 --- a/app/Cli/Commands/AbstractCommand.php +++ b/app/Cli/Commands/AbstractCommand.php @@ -20,6 +20,7 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Cli\Commands; use InvalidArgumentException; +use LogicException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -28,6 +29,15 @@ use function is_string; abstract class AbstractCommand extends Command { + public function __construct() + { + if (PHP_SAPI !== 'cli') { + throw new LogicException('Commands can only run from the command line.'); + } + + parent::__construct(); + } + protected function boolOption(InputInterface $input, string $name): bool { $value = $input->getOption(name: $name); -- cgit v1.3