Skip to content

Commit 951e0d6

Browse files
committed
[make:twig-component]
1 parent c1c9a59 commit 951e0d6

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

src/Maker/MakeTwigComponent.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

1414
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;
1518
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1619
use Symfony\Bundle\MakerBundle\Generator;
1720
use Symfony\Bundle\MakerBundle\InputConfiguration;
@@ -28,6 +31,11 @@
2831
*/
2932
final class MakeTwigComponent extends AbstractMaker
3033
{
34+
public function __construct(
35+
private DependencyManager $dependencyManager = new DependencyManager(),
36+
) {
37+
}
38+
3139
public static function getCommandName(): string
3240
{
3341
return 'make:twig-component';
@@ -49,7 +57,37 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
4957

5058
public function configureDependencies(DependencyBuilder $dependencies): void
5159
{
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+
);
5391
}
5492

5593
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
@@ -87,11 +125,4 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
87125
$io->writeln(" To render the component, use <fg=yellow><twig:{$shortName} /></>.");
88126
$io->newLine();
89127
}
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-
}
97128
}

0 commit comments

Comments
 (0)