1616use Symfony \Bundle \MakerBundle \FileManager ;
1717use Symfony \Bundle \MakerBundle \Generator ;
1818use Symfony \Bundle \MakerBundle \InputConfiguration ;
19+ use Symfony \Bundle \MakerBundle \Security \InteractiveSecurityHelper ;
1920use Symfony \Bundle \MakerBundle \Security \SecurityConfigUpdater ;
2021use Symfony \Bundle \MakerBundle \Util \YamlManipulationFailedException ;
2122use Symfony \Bundle \MakerBundle \Util \YamlSourceManipulator ;
2223use Symfony \Component \Console \Command \Command ;
24+ use Symfony \Component \Console \Exception \InvalidOptionException ;
2325use Symfony \Component \Console \Input \InputArgument ;
2426use Symfony \Bundle \SecurityBundle \SecurityBundle ;
2527use Symfony \Component \Console \Input \InputInterface ;
28+ use Symfony \Component \Console \Input \InputOption ;
29+ use Symfony \Component \Filesystem \Filesystem ;
2630
2731/**
2832 * @author Ryan Weaver <[email protected] > @@ -53,6 +57,22 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
5357 ;
5458 }
5559
60+ public function interact (InputInterface $ input , ConsoleStyle $ io , Command $ command )
61+ {
62+ $ fs = new Filesystem ();
63+
64+ if (!$ fs ->exists ($ path = 'config/packages/security.yaml ' )) {
65+ return ;
66+ }
67+
68+ $ manipulator = new YamlSourceManipulator ($ this ->fileManager ->getFileContents ($ path ));
69+ $ securityData = $ manipulator ->getData ();
70+
71+ $ interactiveSecurityHelper = new InteractiveSecurityHelper ();
72+ $ command ->addOption ('firewall-name ' , null , InputOption::VALUE_OPTIONAL , '' );
73+ $ interactiveSecurityHelper ->guessFirewallName ($ input , $ io , $ securityData );
74+ }
75+
5676 public function generate (InputInterface $ input , ConsoleStyle $ io , Generator $ generator )
5777 {
5878 $ classNameDetails = $ generator ->createClassNameDetails (
@@ -66,14 +86,17 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
6686 []
6787 );
6888
89+ $ securityYamlUpdated = false ;
6990 $ path = 'config/packages/security.yaml ' ;
7091 if ($ this ->fileManager ->fileExists ($ path )) {
7192 try {
7293 $ newYaml = $ this ->configUpdater ->updateForAuthenticator (
7394 $ this ->fileManager ->getFileContents ($ path ),
95+ $ input ->getOption ('firewall-name ' ),
7496 $ classNameDetails ->getFullName ()
7597 );
7698 $ generator ->dumpFile ($ path , $ newYaml );
99+ $ securityYamlUpdated = true ;
77100 } catch (YamlManipulationFailedException $ e ) {
78101 }
79102 }
@@ -82,10 +105,11 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
82105
83106 $ this ->writeSuccessMessage ($ io );
84107
85- $ io ->text ([
86- 'Next: Customize your new authenticator. ' ,
87- 'Then, configure the "guard" key on your firewall to use it. ' ,
88- ]);
108+ $ text = ['Next: Customize your new authenticator. ' ];
109+ if (!$ securityYamlUpdated ) {
110+ $ text [] = 'Then, configure the "guard" key on your firewall to use it. ' ;
111+ }
112+ $ io ->text ($ text );
89113 }
90114
91115 public function configureDependencies (DependencyBuilder $ dependencies )
0 commit comments