diff --git a/composer.json b/composer.json index 48f852f8..8c89570d 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "psr/http-message-implementation": "^1.0 || ^2.0", "psr/http-server-handler": "^1.0.2", "psr/log": "^1.0 || ^2.0 || ^3.0", - "symfony/console": "^5.0 || ^6.0.19 || ^7.0", + "symfony/console": "^5.3 || ^6.0.19 || ^7.0", "webmozart/assert": "^1.11" }, "require-dev": { diff --git a/composer.lock b/composer.lock index dc3c7010..091fd779 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1152a47b1909953f72cae4ad39b97f2f", + "content-hash": "7889e27593f51ecf32844e51c3c17e59", "packages": [ { "name": "dflydev/fig-cookies", diff --git a/src/Command/ReloadCommand.php b/src/Command/ReloadCommand.php index 02d27b5a..782f8be0 100644 --- a/src/Command/ReloadCommand.php +++ b/src/Command/ReloadCommand.php @@ -9,6 +9,7 @@ namespace Mezzio\Swoole\Command; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -19,6 +20,7 @@ use const SWOOLE_PROCESS; +#[AsCommand('mezzio:swoole:reload')] class ReloadCommand extends Command { /** @@ -33,9 +35,6 @@ class ReloadCommand extends Command configuration value is set to SWOOLE_PROCESS. EOH; - /** @var null|string Cannot be defined explicitly due to parent class */ - public static $defaultName = 'mezzio:swoole:reload'; - public function __construct(private int $serverMode) { parent::__construct(); @@ -73,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var Application $application */ $application = $this->getApplication(); - $stop = $application->find(StopCommand::$defaultName); + $stop = $application->find(StopCommand::getDefaultName()); $result = $stop->run(new ArrayInput([ 'command' => 'stop', ]), $output); @@ -92,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('[DONE]'); $output->writeln('Starting server'); - $start = $application->find(StartCommand::$defaultName); + $start = $application->find(StartCommand::getDefaultName()); $inputArguments = [ 'command' => 'start', diff --git a/src/Command/StartCommand.php b/src/Command/StartCommand.php index 44742d77..911ab9eb 100644 --- a/src/Command/StartCommand.php +++ b/src/Command/StartCommand.php @@ -13,6 +13,7 @@ use Mezzio\Swoole\PidManager; use Psr\Container\ContainerInterface; use Swoole\Http\Server as SwooleHttpServer; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -20,6 +21,7 @@ use function file_exists; +#[AsCommand('mezzio:swoole:start')] class StartCommand extends Command { use IsRunningTrait; @@ -51,9 +53,6 @@ class StartCommand extends Command 'config/routes.php', ]; - /** @var null|string Cannot be defined explicitly due to parent class */ - public static $defaultName = 'mezzio:swoole:start'; - public function __construct(private ContainerInterface $container) { parent::__construct(); diff --git a/src/Command/StatusCommand.php b/src/Command/StatusCommand.php index 1b212044..963fe71b 100644 --- a/src/Command/StatusCommand.php +++ b/src/Command/StatusCommand.php @@ -9,10 +9,12 @@ namespace Mezzio\Swoole\Command; use Mezzio\Swoole\PidManager; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand('mezzio:swoole:status')] class StatusCommand extends Command { use IsRunningTrait; @@ -27,9 +29,6 @@ class StatusCommand extends Command --daemonize option. EOH; - /** @var null|string Cannot be defined explicitly due to parent class */ - public static $defaultName = 'mezzio:swoole:status'; - public function __construct(private PidManager $pidManager) { parent::__construct(); diff --git a/src/Command/StopCommand.php b/src/Command/StopCommand.php index 32fc76b6..46cb71e9 100644 --- a/src/Command/StopCommand.php +++ b/src/Command/StopCommand.php @@ -11,6 +11,7 @@ use Closure; use Mezzio\Swoole\PidManager; use Swoole\Process as SwooleProcess; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -18,6 +19,7 @@ use function time; use function usleep; +#[AsCommand('mezzio:swoole:stop')] class StopCommand extends Command { use IsRunningTrait; @@ -32,9 +34,6 @@ class StopCommand extends Command --daemonize option. EOH; - /** @var null|string Cannot be defined explicitly due to parent class */ - public static $defaultName = 'mezzio:swoole:stop'; - /** * @internal * diff --git a/test/Command/ReloadCommandTest.php b/test/Command/ReloadCommandTest.php index 9253abe6..c69e0fc8 100644 --- a/test/Command/ReloadCommandTest.php +++ b/test/Command/ReloadCommandTest.php @@ -149,7 +149,7 @@ public function testExecuteEndsWithErrorWhenStopCommandFails(): void ->willReturn(1); $application = $this->mockApplication(); - $application->method('find')->with(StopCommand::$defaultName)->willReturn($stopCommand); + $application->method('find')->with(StopCommand::getDefaultName())->willReturn($stopCommand); $command->setApplication($application); @@ -200,8 +200,8 @@ public function testExecuteEndsWithErrorWhenStartCommandFails(): void ->expects($this->exactly(2)) ->method('find') ->willReturnMap([ - [StopCommand::$defaultName, $stopCommand], - [StartCommand::$defaultName, $startCommand], + [StopCommand::getDefaultName(), $stopCommand], + [StartCommand::getDefaultName(), $startCommand], ]); $command->setApplication($application); @@ -270,8 +270,8 @@ public function testExecuteEndsWithSuccessWhenBothStopAndStartCommandsSucceed(): ->expects($this->exactly(2)) ->method('find') ->willReturnMap([ - [StopCommand::$defaultName, $stopCommand], - [StartCommand::$defaultName, $startCommand], + [StopCommand::getDefaultName(), $stopCommand], + [StartCommand::getDefaultName(), $startCommand], ]); $this->output