Skip to content

Commit 66f3d54

Browse files
committed
bug #165 [LiveComponent] fix silent serializer/doctrine dependency issue (kbond)
This PR was merged into the main branch. Discussion ---------- [LiveComponent] fix silent serializer/doctrine dependency issue | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | Fix #164 | License | MIT Commits ------- da043dc [LiveComponent] fix silent serializer/doctrine dependency issue (fixes #164)
2 parents 1ab8dcc + da043dc commit 66f3d54

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Symfony\UX\LiveComponent\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Reference;
8+
use Symfony\UX\LiveComponent\Hydrator\DoctrineEntityPropertyHydrator;
9+
use Symfony\UX\LiveComponent\Hydrator\NormalizerBridgePropertyHydrator;
10+
11+
/**
12+
* @author Kevin Bond <[email protected]>
13+
*/
14+
final class OptionalDependencyPass implements CompilerPassInterface
15+
{
16+
public function process(ContainerBuilder $container): void
17+
{
18+
if ($container->hasDefinition('doctrine')) {
19+
$container->register('ux.live_component.doctrine_entity_property_hydrator', DoctrineEntityPropertyHydrator::class)
20+
->setArguments([[new Reference('doctrine')]])
21+
->addTag('twig.component.property_hydrator', ['priority' => -100])
22+
;
23+
}
24+
25+
if ($container->hasDefinition('serializer')) {
26+
$container->register('ux.live_component.serializer_property_hydrator', NormalizerBridgePropertyHydrator::class)
27+
->setArguments([new Reference('serializer')])
28+
->addTag('twig.component.property_hydrator', ['priority' => -200])
29+
;
30+
}
31+
}
32+
}

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
use Symfony\UX\LiveComponent\ComponentValidator;
2323
use Symfony\UX\LiveComponent\ComponentValidatorInterface;
2424
use Symfony\UX\LiveComponent\EventListener\LiveComponentSubscriber;
25-
use Symfony\UX\LiveComponent\Hydrator\DoctrineEntityPropertyHydrator;
26-
use Symfony\UX\LiveComponent\Hydrator\NormalizerBridgePropertyHydrator;
2725
use Symfony\UX\LiveComponent\LiveComponentHydrator;
2826
use Symfony\UX\LiveComponent\PropertyHydratorInterface;
2927
use Symfony\UX\LiveComponent\Twig\LiveComponentExtension as LiveComponentTwigExtension;
@@ -60,16 +58,6 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
6058
->addTag('twig.component.property_hydrator')
6159
;
6260

63-
$container->register('ux.live_component.doctrine_entity_property_hydrator', DoctrineEntityPropertyHydrator::class)
64-
->setArguments([[new Reference('doctrine')]])
65-
->addTag('twig.component.property_hydrator', ['priority' => -100])
66-
;
67-
68-
$container->register('ux.live_component.serializer_property_hydrator', NormalizerBridgePropertyHydrator::class)
69-
->setArguments([new Reference('serializer')])
70-
->addTag('twig.component.property_hydrator', ['priority' => -200])
71-
;
72-
7361
$container->register('ux.live_component.component_hydrator', LiveComponentHydrator::class)
7462
->setArguments([
7563
new TaggedIteratorArgument('twig.component.property_hydrator'),

src/LiveComponent/src/LiveComponentBundle.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\UX\LiveComponent;
1313

14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1415
use Symfony\Component\HttpKernel\Bundle\Bundle;
16+
use Symfony\UX\LiveComponent\DependencyInjection\Compiler\OptionalDependencyPass;
1517

1618
/**
1719
* @author Kevin Bond <[email protected]>
@@ -20,4 +22,8 @@
2022
*/
2123
final class LiveComponentBundle extends Bundle
2224
{
25+
public function build(ContainerBuilder $container): void
26+
{
27+
$container->addCompilerPass(new OptionalDependencyPass());
28+
}
2329
}

0 commit comments

Comments
 (0)