12
12
namespace Symfony \Bundle \MakerBundle \Maker ;
13
13
14
14
use Symfony \Bundle \MakerBundle \ConsoleStyle ;
15
+ use Symfony \Bundle \MakerBundle \Dependency \DependencyManager ;
16
+ use Symfony \Bundle \MakerBundle \Dependency \Model \OptionalClassDependency ;
17
+ use Symfony \Bundle \MakerBundle \Dependency \Model \RequiredClassDependency ;
15
18
use Symfony \Bundle \MakerBundle \DependencyBuilder ;
16
19
use Symfony \Bundle \MakerBundle \Generator ;
17
20
use Symfony \Bundle \MakerBundle \InputConfiguration ;
28
31
*/
29
32
final class MakeTwigComponent extends AbstractMaker
30
33
{
34
+ public function __construct (
35
+ private DependencyManager $ dependencyManager = new DependencyManager (),
36
+ ) {
37
+ }
38
+
31
39
public static function getCommandName (): string
32
40
{
33
41
return 'make:twig-component ' ;
@@ -49,7 +57,37 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
49
57
50
58
public function configureDependencies (DependencyBuilder $ dependencies ): void
51
59
{
52
- $ dependencies ->addClassDependency (AsTwigComponent::class, 'symfony/ux-twig-component ' );
60
+ $ this ->dependencyManager
61
+ ->addRequiredDependency (new RequiredClassDependency (
62
+ AsTwigComponent::class,
63
+ 'symfony/ux-twig-component ' ,
64
+ ))
65
+ ->addOptionalDependency (new OptionalClassDependency (
66
+ AsLiveComponent::class,
67
+ 'symfony/ux-live-component ' ,
68
+ ))
69
+ ;
70
+ }
71
+
72
+ public function interact (InputInterface $ input , ConsoleStyle $ io , Command $ command ): void
73
+ {
74
+ $ this ->dependencyManager ->installRequiredDependencies (
75
+ io: $ io ,
76
+ preInstallMessage: 'This command requires the Symfony UX Twig Component Package. '
77
+ );
78
+
79
+ if (!$ input ->getOption ('live ' )) {
80
+ $ input ->setOption ('live ' , $ io ->confirm ('Make this a live component? ' ));
81
+ }
82
+
83
+ if (!$ input ->getOption ('live ' )) {
84
+ return ;
85
+ }
86
+
87
+ $ this ->dependencyManager ->installOptionalDependencies (
88
+ io: $ io ,
89
+ preInstallMessage: 'The Symfony UX Live Component is needed to make this a live component. '
90
+ );
53
91
}
54
92
55
93
public function generate (InputInterface $ input , ConsoleStyle $ io , Generator $ generator ): void
@@ -87,11 +125,4 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
87
125
$ io ->writeln (" To render the component, use <fg=yellow><twig: {$ shortName } /></>. " );
88
126
$ io ->newLine ();
89
127
}
90
-
91
- public function interact (InputInterface $ input , ConsoleStyle $ io , Command $ command ): void
92
- {
93
- if (!$ input ->getOption ('live ' )) {
94
- $ input ->setOption ('live ' , $ io ->confirm ('Make this a live component? ' , class_exists (AsLiveComponent::class)));
95
- }
96
- }
97
128
}
0 commit comments