Skip to content

Commit 1b934e5

Browse files
committed
allow command security:custom with name in argument to no interraction
1 parent fb404cc commit 1b934e5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/Maker/Security/MakeCustomAuthenticator.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
2525
use Symfony\Bundle\MakerBundle\Validator;
2626
use Symfony\Component\Console\Command\Command;
27+
use Symfony\Component\Console\Input\InputArgument;
2728
use Symfony\Component\Console\Input\InputInterface;
2829
use Symfony\Component\HttpFoundation\JsonResponse;
2930
use Symfony\Component\HttpFoundation\Request;
@@ -68,8 +69,11 @@ public static function getCommandDescription(): string
6869
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
6970
{
7071
$command
72+
->addArgument('name', InputArgument::OPTIONAL, 'The class name of the authenticator (e.g. <fg=yellow>CustomAuthenticator</>)')
7173
->setHelp(file_get_contents(__DIR__.'/../../Resources/help/security/MakeCustom.txt'))
7274
;
75+
76+
$inputConfig->setArgumentAsNonInteractive('name');
7377
}
7478

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

87-
$name = $io->ask(
88-
question: 'What is the class name of the authenticator (e.g. <fg=yellow>CustomAuthenticator</>)',
89-
validator: static function (mixed $answer) {
90-
return Validator::notBlank($answer);
91-
}
92-
);
91+
if (null === $input->getArgument('name')) {
92+
$input->setArgument('name', $io->ask(
93+
question: 'What is the class name of the authenticator (e.g. <fg=yellow>CustomAuthenticator</>)',
94+
validator: static function (mixed $answer) {
95+
return Validator::notBlank($answer);
96+
}
97+
));
98+
}
99+
}
93100

101+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
102+
{
94103
$this->authenticatorClassName = $this->generator->createClassNameDetails(
95-
name: $name,
104+
name: $input->getArgument('name'),
96105
namespacePrefix: 'Security\\',
97106
suffix: 'Authenticator'
98107
);
99-
}
100108

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

0 commit comments

Comments
 (0)