Skip to content

Commit 351dfde

Browse files
author
matheo
committed
add configuration for template extension
1 parent a3cf1f9 commit 351dfde

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/TwigComponent/src/ComponentFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct(
3535
private EventDispatcherInterface $eventDispatcher,
3636
private array $config,
3737
private Environment $environment,
38+
private string $twigExtension
3839
) {
3940
}
4041

@@ -48,7 +49,7 @@ public function metadataFor(string $name): ComponentMetadata
4849
]);
4950
}
5051

51-
throw new \InvalidArgumentException(sprintf('Unknown component "%s". The registered components are: %s', $name, implode(', ', array_keys($this->config))));
52+
throw new \InvalidArgumentException(sprintf('Unknown component "%s". The registered components are: %s. And no template %s. founded', $name, implode(', ', array_keys($this->config)), $this->getTemplateFromName($name)));
5253
}
5354

5455
return new ComponentMetadata($config);
@@ -156,7 +157,7 @@ private function getComponent(string $name): object
156157
return new StaticComponent();
157158
}
158159

159-
throw new \InvalidArgumentException(sprintf('Unknown component "%s". The registered components are: %s', $name, implode(', ', array_keys($this->components->getProvidedServices()))));
160+
throw new \InvalidArgumentException(sprintf('Unknown component "%s". The registered components are: %s. And no template %s. founded', $name, implode(', ', array_keys($this->components->getProvidedServices())), $this->getTemplateFromName($name)));
160161
}
161162

162163
return $this->components->get($name);
@@ -203,6 +204,6 @@ private function isStaticComponent(string $name): bool
203204

204205
private function getTemplateFromName(string $name): string
205206
{
206-
return str_replace('.', '/', $name).'.html.twig';
207+
return str_replace('.', '/', $name).$this->twigExtension;
207208
}
208209
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Symfony\UX\TwigComponent\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
class Configuration implements ConfigurationInterface
9+
{
10+
public function getConfigTreeBuilder(): TreeBuilder
11+
{
12+
$treeBuilder = new TreeBuilder('twig_component');
13+
$rootNode = $treeBuilder->getRootNode();
14+
$rootNode
15+
->children()
16+
->scalarNode('twig_extension')->defaultValue('.html.twig')->end()
17+
->end()
18+
;
19+
20+
return $treeBuilder;
21+
}
22+
}

src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public function load(array $configs, ContainerBuilder $container): void
4040
throw new LogicException('The TwigBundle is not registered in your application. Try running "composer require symfony/twig-bundle".');
4141
}
4242

43+
$configuration = new Configuration();
44+
$config = $this->processConfiguration($configuration, $configs);
45+
4346
$container->registerAttributeForAutoconfiguration(
4447
AsTwigComponent::class,
4548
static function (ChildDefinition $definition, AsTwigComponent $attribute) {
@@ -54,6 +57,7 @@ static function (ChildDefinition $definition, AsTwigComponent $attribute) {
5457
new Reference('event_dispatcher'),
5558
class_exists(AbstractArgument::class) ? new AbstractArgument(sprintf('Added in %s.', TwigComponentPass::class)) : [],
5659
new Reference('twig'),
60+
$config['twig_extension'],
5761
])
5862
;
5963

0 commit comments

Comments
 (0)