Skip to content

[TwigComponent] Support for SubDirectory-named components via namespace config #1140

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/LiveComponent/tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,42 @@ public function process(ContainerBuilder $container): void

protected function configureContainer(ContainerConfigurator $c): void
{
$c->extension('framework', [
$frameworkConfig = [
'secret' => 'S3CRET',
'test' => true,
'router' => ['utf8' => true],
'secrets' => false,
'session' => ['storage_factory_id' => 'session.storage.factory.mock_file'],
'session' => [
'storage_factory_id' => 'session.storage.factory.mock_file',
'handler_id' => null,
'cookie_secure' => 'auto',
'cookie_samesite' => 'lax',
],
'validation' => [
'email_validation_mode' => 'html5',
],
'php_errors' => [
'log' => false,
],
'http_method_override' => false,
'property_info' => ['enabled' => true],
]);
];
if (self::VERSION_ID >= 60200) {
$frameworkConfig['handle_all_throwables'] = true;
}

$c->extension('framework', $frameworkConfig);

$c->extension('twig', [
'default_path' => '%kernel.project_dir%/tests/Fixtures/templates',
]);

$c->extension('twig_component', [
'defaults' => [
'Symfony\UX\LiveComponent\Tests\Fixtures\Component\\' => 'components/',
],
]);

$c->extension('zenstruck_foundry', [
'auto_refresh_proxies' => false,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public function __construct(private ManagerRegistry $doctrine)
{
}

public function denormalize(mixed $data, string $type, string $format = null, array $context = [])
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
{
[, $id] = \explode(':', $data);

return $this->doctrine->getRepository(Entity2::class)->find($id);
}

public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = [])
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
{
return Entity2::class === $type;
}

public function normalize(mixed $object, string $format = null, array $context = [])
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
return 'entity2:'.$object->id;
}

public function supportsNormalization(mixed $data, string $format = null, array $context = [])
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
{
return $data instanceof Entity2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

final class MoneyNormalizer implements NormalizerInterface, DenormalizerInterface
{
public function denormalize(mixed $data, string $type, string $format = null, array $context = [])
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
{
return new Money(...\explode('|', $data));
}

public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = [])
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
{
return Money::class === $type;
}

public function normalize(mixed $object, string $format = null, array $context = [])
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
return \implode('|', [$object->amount, $object->currency]);
}

public function supportsNormalization(mixed $data, string $format = null, array $context = [])
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
{
return $data instanceof Money;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.php');

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$config = $this->processConfiguration($this, $configs);

$container->findDefinition('stimulus.asset_mapper.controllers_map_generator')
->replaceArgument(2, $config['controller_paths'])
Expand Down Expand Up @@ -64,11 +63,6 @@ public function prepend(ContainerBuilder $container)
]);
}

public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
{
return $this;
}

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('stimulus');
Expand Down
Loading