From 90ac65e152e3be3f1329fcc53323b820d6419ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Guti=C3=A9rrez?= Date: Fri, 2 Feb 2024 20:55:32 +0100 Subject: [PATCH] support symfony console 7 --- composer.json | 8 ++++---- src/Console/ListCommand.php | 5 ++--- src/Console/MatchCommand.php | 6 ++---- src/Mapping/Driver/FileMappingTrait.php | 4 +++- src/Mapping/Metadata/RouteMetadata.php | 4 +++- tests/Routing/Console/MatchCommandTest.php | 6 +++--- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 5462125..7f91252 100644 --- a/composer.json +++ b/composer.json @@ -45,14 +45,14 @@ "roave/security-advisories": "dev-master", "slim/twig-view": "^3.3", "spatie/array-to-xml": "^3.2", - "symfony/console": "^6.0", - "symfony/yaml": "^6.0" + "symfony/console": "^6.0|^7.0", + "symfony/yaml": "^6.0|^7.0" }, "suggest": { "slim/twig-view": "In order to return Twig rendered responses (>=3.3)", "spatie/array-to-xml": "In order to return XML responses (>=3.2)", - "symfony/yaml": "In order to load routing from YAML files (>=5.1)", - "symfony/console": "In order to use console commands (>=5.1)" + "symfony/yaml": "In order to load routing from YAML files (>=6.0)", + "symfony/console": "In order to use console commands (>=6.0)" }, "autoload": { "psr-4": { diff --git a/src/Console/ListCommand.php b/src/Console/ListCommand.php index 6ca7f19..f25c7b3 100644 --- a/src/Console/ListCommand.php +++ b/src/Console/ListCommand.php @@ -13,6 +13,7 @@ use Jgut\Slim\Routing\RouteCollector; use Slim\Interfaces\RouteInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -20,15 +21,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'slim:routing:list')] class ListCommand extends AbstractRoutingCommand { - public const NAME = 'slim:routing:list'; private const SORT_PRIORITY = 'priority'; private const SORT_PATH = 'path'; private const SORT_NAME = 'name'; - protected static $defaultName = self::NAME; - public function __construct( private RouteCollector $routeCollector, ?string $name = null, diff --git a/src/Console/MatchCommand.php b/src/Console/MatchCommand.php index 0b944a1..fd99821 100644 --- a/src/Console/MatchCommand.php +++ b/src/Console/MatchCommand.php @@ -14,18 +14,16 @@ use Slim\Interfaces\RouteInterface; use Slim\Interfaces\RouteResolverInterface; use Slim\Routing\RoutingResults; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'slim:routing:match')] class MatchCommand extends AbstractRoutingCommand { - public const NAME = 'slim:routing:match'; - - protected static $defaultName = self::NAME; - public function __construct( private RouteResolverInterface $routeResolver, ?string $name = null, diff --git a/src/Mapping/Driver/FileMappingTrait.php b/src/Mapping/Driver/FileMappingTrait.php index 02edbd3..98d3c8a 100644 --- a/src/Mapping/Driver/FileMappingTrait.php +++ b/src/Mapping/Driver/FileMappingTrait.php @@ -221,7 +221,9 @@ protected function populateMethods(RouteMetadata $metadata, array $mapping): voi $methods[] = trim($method); } - $methods = array_unique(array_filter($methods, 'strlen')); + /** @var callable $callable */ + $callable = 'strlen'; + $methods = array_unique(array_filter($methods, $callable)); if (\count($methods) === 0) { throw new DriverException('Route methods can not be empty.'); diff --git a/src/Mapping/Metadata/RouteMetadata.php b/src/Mapping/Metadata/RouteMetadata.php index 3de0739..77ab885 100644 --- a/src/Mapping/Metadata/RouteMetadata.php +++ b/src/Mapping/Metadata/RouteMetadata.php @@ -145,7 +145,9 @@ public function setMethods(array $methods): self $methodList[] = mb_strtoupper(trim($method)); } - $methodList = array_filter($methodList, 'strlen'); + /** @var callable $callable */ + $callable = 'strlen'; + $methodList = array_filter($methodList, $callable); if (\count($methodList) === 0) { throw new MetadataException('Route methods can not be empty.'); diff --git a/tests/Routing/Console/MatchCommandTest.php b/tests/Routing/Console/MatchCommandTest.php index aea8845..1603b4e 100644 --- a/tests/Routing/Console/MatchCommandTest.php +++ b/tests/Routing/Console/MatchCommandTest.php @@ -45,7 +45,7 @@ public function testNoRoutes(): void $command = new MatchCommand($routeResolver); - $input = new ArgvInput([MatchCommand::NAME, '/home', 'get'], $command->getDefinition()); + $input = new ArgvInput([MatchCommand::getDefaultName(), '/home', 'get'], $command->getDefinition()); $output = new ConsoleOutputStub(); @@ -98,8 +98,8 @@ static function ( $command = new MatchCommand($routeResolver); $input = $method !== null - ? new ArgvInput([MatchCommand::NAME, $path, $method], $command->getDefinition()) - : new ArgvInput([MatchCommand::NAME, $path], $command->getDefinition()); + ? new ArgvInput([MatchCommand::getDefaultName(), $path, $method], $command->getDefinition()) + : new ArgvInput([MatchCommand::getDefaultName(), $path], $command->getDefinition()); $output = new ConsoleOutputStub();