Skip to content

Commit

Permalink
allow command security:custom with name in argument to no interraction
Browse files Browse the repository at this point in the history
  • Loading branch information
eltharin committed Sep 17, 2024
1 parent fb404cc commit 1b934e5
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/Maker/Security/MakeCustomAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -68,8 +69,11 @@ public static function getCommandDescription(): string
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->addArgument('name', InputArgument::OPTIONAL, 'The class name of the authenticator (e.g. <fg=yellow>CustomAuthenticator</>)')
->setHelp(file_get_contents(__DIR__.'/../../Resources/help/security/MakeCustom.txt'))
;

$inputConfig->setArgumentAsNonInteractive('name');
}

public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
Expand All @@ -84,22 +88,24 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
throw new RuntimeCommandException(\sprintf('The file "%s" does not exist. PHP & XML configuration formats are currently not supported.', self::SECURITY_CONFIG_PATH));
}

$name = $io->ask(
question: 'What is the class name of the authenticator (e.g. <fg=yellow>CustomAuthenticator</>)',
validator: static function (mixed $answer) {
return Validator::notBlank($answer);
}
);
if (null === $input->getArgument('name')) {
$input->setArgument('name', $io->ask(
question: 'What is the class name of the authenticator (e.g. <fg=yellow>CustomAuthenticator</>)',
validator: static function (mixed $answer) {
return Validator::notBlank($answer);
}
));
}
}

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
{
$this->authenticatorClassName = $this->generator->createClassNameDetails(
name: $name,
name: $input->getArgument('name'),
namespacePrefix: 'Security\\',
suffix: 'Authenticator'
);
}

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
{
// Configure security to use custom authenticator
$securityConfig = ($ysm = new YamlSourceManipulator(
$this->fileManager->getFileContents(self::SECURITY_CONFIG_PATH)
Expand Down

0 comments on commit 1b934e5

Please sign in to comment.