Skip to content

Commit

Permalink
support symfony console 7
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Feb 2, 2024
1 parent 5bc6933 commit 90ac65e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 2 additions & 3 deletions src/Console/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@

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;
use Symfony\Component\Console\Input\InputOption;
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,
Expand Down
6 changes: 2 additions & 4 deletions src/Console/MatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/Mapping/Driver/FileMappingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
4 changes: 3 additions & 1 deletion src/Mapping/Metadata/RouteMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
6 changes: 3 additions & 3 deletions tests/Routing/Console/MatchCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 90ac65e

Please sign in to comment.