From f977f7886aa23a6152f0b045d06b3c218ead6625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ondr=C3=A1=C4=8Dek?= Date: Fri, 5 Dec 2025 02:15:45 +0100 Subject: [PATCH 1/3] Composer: require PHP 8.2+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roman Ondráček --- .github/workflows/tests.yml | 8 +------- README.md | 2 +- composer.json | 2 +- phpstan.neon | 2 +- ruleset.xml | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7f75a28..0bdeea0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,15 +35,9 @@ jobs: with: php: "8.2" - test81: - name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@master - with: - php: "8.1" - testlower: name: "Nette Tester" uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.1" + php: "8.2" composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" diff --git a/README.md b/README.md index eec4e60..4957a7e 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ For details on how to use this package, check out our [documentation](.docs). | State | Version | Branch | Nette | PHP | |--------|-----------|----------|--------|---------| -| dev | `^0.11.0` | `master` | `3.2+` | `>=8.1` | +| dev | `^0.11.0` | `master` | `3.2+` | `>=8.2` | | stable | `^0.10.0` | `master` | `3.2+` | `>=8.1` | diff --git a/composer.json b/composer.json index e65898e..8cec154 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=8.1", + "php": ">=8.2", "nette/di": "^3.1.8", "symfony/console": "^6.4.2 || ^7.0.2" }, diff --git a/phpstan.neon b/phpstan.neon index 562ab05..16b3197 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ includes: parameters: level: 9 - phpVersion: 80100 + phpVersion: 80200 scanDirectories: - src diff --git a/ruleset.xml b/ruleset.xml index 6bf9efb..e195751 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,7 +1,7 @@ - + From 205d6b085d13d191eb28ce3e534be93c20719a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ondr=C3=A1=C4=8Dek?= Date: Fri, 5 Dec 2025 02:17:33 +0100 Subject: [PATCH 2/3] Composer: allow Symfony 8.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roman Ondráček --- composer.json | 8 ++++---- src/DI/ConsoleExtension.php | 32 ++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 8cec154..6def0c3 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ "require": { "php": ">=8.2", "nette/di": "^3.1.8", - "symfony/console": "^6.4.2 || ^7.0.2" + "symfony/console": "^6.4.2 || ^7.0.2 || ^8.0.0" }, "require-dev": { "nette/http": "^3.2.3", "contributte/qa": "^0.4", "contributte/tester": "^0.4", - "contributte/phpstan": "^0.1", - "mockery/mockery": "^1.6.7", - "symfony/event-dispatcher": "^6.4.2 || ^7.0.2" + "contributte/phpstan": "^0.2", + "mockery/mockery": "^1.6.12", + "symfony/event-dispatcher": "^6.4.2 || ^7.0.2 || ^8.0.0" }, "autoload": { "psr-4": { diff --git a/src/DI/ConsoleExtension.php b/src/DI/ConsoleExtension.php index 0617457..9d5bc44 100644 --- a/src/DI/ConsoleExtension.php +++ b/src/DI/ConsoleExtension.php @@ -14,7 +14,10 @@ use Nette\Schema\Expect; use Nette\Schema\Schema; use Nette\Utils\Arrays; +use ReflectionClass; +use ReflectionProperty; use stdClass; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -25,11 +28,10 @@ class ConsoleExtension extends CompilerExtension { - private bool $cliMode; - - public function __construct(bool $cliMode = false) + public function __construct( + private readonly bool $cliMode = false, + ) { - $this->cliMode = $cliMode; } public function getConfigSchema(): Schema @@ -158,10 +160,23 @@ public function beforeCompile(): void } $aliases = []; - // Try to detect command name from Command::getDefaultName() - if ($commandName === null) { - $commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line - if ($commandName === null) { + // Try to detect command name from Command::getDefaultName() or Command::defaultName property + if (!is_string($commandName) || $commandName === '') { + /** @var class-string $className */ + $className = $service->getType(); + $reflection = new ReflectionClass($className); + $attributes = $reflection->getAttributes(AsCommand::class); + + if ($attributes !== []) { + $commandName = $attributes[0]->newInstance()->name; + } elseif (method_exists($className, 'getDefaultName')) { + $commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line + } elseif (property_exists($className, 'defaultName')) { + $rp = new ReflectionProperty($className, 'defaultName'); + $commandName = $rp->getValue(); + } + + if (!is_string($commandName) || $commandName === '') { throw new ServiceCreationException( sprintf( 'Command "%s" missing #[AsCommand] attribute', @@ -169,6 +184,7 @@ public function beforeCompile(): void ) ); } + $aliases = explode('|', $commandName); $commandName = array_shift($aliases); if ($commandName === '') { From 7334cf90ae288b59193350fc63e66c9faf3aca9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ondr=C3=A1=C4=8Dek?= Date: Fri, 5 Dec 2025 02:33:51 +0100 Subject: [PATCH 3/3] Use PHP 8.2 syntax sugar and fix issues reported by PHPStan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roman Ondráček --- src/CommandLoader/ContainerCommandLoader.php | 12 ++++-------- src/Http/ConsoleRequestFactory.php | 7 +++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/CommandLoader/ContainerCommandLoader.php b/src/CommandLoader/ContainerCommandLoader.php index 7d45f96..a895058 100644 --- a/src/CommandLoader/ContainerCommandLoader.php +++ b/src/CommandLoader/ContainerCommandLoader.php @@ -10,18 +10,14 @@ class ContainerCommandLoader implements CommandLoaderInterface { - private Container $container; - - /** @var array */ - private array $commandMap; - /** * @param array $commandMap */ - public function __construct(Container $container, array $commandMap) + public function __construct( + private readonly Container $container, + private readonly array $commandMap, + ) { - $this->container = $container; - $this->commandMap = $commandMap; } public function get(string $name): Command diff --git a/src/Http/ConsoleRequestFactory.php b/src/Http/ConsoleRequestFactory.php index 31c70ed..25bc944 100644 --- a/src/Http/ConsoleRequestFactory.php +++ b/src/Http/ConsoleRequestFactory.php @@ -9,11 +9,10 @@ class ConsoleRequestFactory extends RequestFactory { - private string $url; - - public function __construct(string $url) + public function __construct( + private readonly string $url, + ) { - $this->url = $url; } public function fromGlobals(): Request