Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:twig-component] Improve make:twig-component by reading the configuration file #1571

Merged
merged 14 commits into from
Jun 18, 2024
18 changes: 17 additions & 1 deletion src/Maker/MakeTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Yaml\Yaml;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

Expand All @@ -27,6 +29,12 @@
*/
final class MakeTwigComponent extends AbstractMaker
{
private string $namespace = 'Twig\\Components';

public function __construct(private FileManager $fileManager)
{
}

public static function getCommandName(): string
{
return 'make:twig-component';
Expand Down Expand Up @@ -62,7 +70,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen

$factory = $generator->createClassNameDetails(
$name,
'Twig\\Components',
$this->namespace,
);

$templatePath = str_replace('\\', '/', $factory->getRelativeNameWithoutSuffix());
Expand Down Expand Up @@ -93,5 +101,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
if (!$input->getOption('live')) {
$input->setOption('live', $io->confirm('Make this a live component?', false));
}

$path = 'config/packages/twig_component.yaml';

if ($this->fileManager->fileExists($path)) {
$value = Yaml::parse($this->fileManager->getFileContents($path));

$this->namespace = substr(array_key_first($value['twig_component']['defaults']), 4);
}
}
}
1 change: 1 addition & 0 deletions src/Resources/config/makers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<service id="maker.maker.make_twig_component" class="Symfony\Bundle\MakerBundle\Maker\MakeTwigComponent">
<tag name="maker.command" />
<argument type="service" id="maker.file_manager" />
</service>

<service id="maker.maker.make_controller" class="Symfony\Bundle\MakerBundle\Maker\MakeController">
Expand Down
Loading