Skip to content

Commit 2710215

Browse files
committed
[WIP][Live] migrate Hydration system to standard Symfony normalizers
1 parent e2df324 commit 2710215

10 files changed

+391
-412
lines changed

src/LiveComponent/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
+ <div {{ attributes }}>
2222
```
2323

24+
- [BC BREAK] Replace property hydration system with `symfony/serializer` normalizers. This
25+
is a BC break if you've created custom hydrators. They'll need to be converted to
26+
normalizers.
27+
2428
## 2.0.0
2529

2630
- Support for `stimulus` version 2 was removed and support for `@hotwired/stimulus`

src/LiveComponent/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"require": {
2929
"php": ">=8.0",
30+
"symfony/serializer": "^5.4|^6.0",
3031
"symfony/ux-twig-component": "^2.1"
3132
},
3233
"require-dev": {
@@ -38,7 +39,6 @@
3839
"symfony/framework-bundle": "^5.4|^6.0",
3940
"symfony/phpunit-bridge": "^6.0",
4041
"symfony/security-csrf": "^5.4|^6.0",
41-
"symfony/serializer": "^5.4|^6.0",
4242
"symfony/twig-bundle": "^5.4|^6.0",
4343
"symfony/validator": "^5.4|^6.0",
4444
"zenstruck/browser": "^0.9.1",

src/LiveComponent/src/DependencyInjection/Compiler/OptionalDependencyPass.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Symfony\UX\LiveComponent\DependencyInjection\Compiler;
44

5+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
56
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
67
use Symfony\Component\DependencyInjection\ContainerBuilder;
78
use Symfony\Component\DependencyInjection\Reference;
8-
use Symfony\UX\LiveComponent\Hydrator\DoctrineEntityPropertyHydrator;
9-
use Symfony\UX\LiveComponent\Hydrator\NormalizerBridgePropertyHydrator;
9+
use Symfony\UX\LiveComponent\Normalizer\DoctrineObjectNormalizer;
1010

1111
/**
1212
* @author Kevin Bond <[email protected]>
@@ -16,16 +16,9 @@ final class OptionalDependencyPass implements CompilerPassInterface
1616
public function process(ContainerBuilder $container): void
1717
{
1818
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])
19+
$container->register('ux.live_component.doctrine_object_normalizer', DoctrineObjectNormalizer::class)
20+
->setArguments([new IteratorArgument([new Reference('doctrine')])]) // todo add other object managers (mongo)
21+
->addTag('serializer.normalizer', ['priority' => 100])
2922
;
3023
}
3124
}

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

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

1212
namespace Symfony\UX\LiveComponent\DependencyInjection;
1313

14-
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1514
use Symfony\Component\DependencyInjection\ChildDefinition;
1615
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Extension\Extension;
1817
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1919
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2020
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2121
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
@@ -24,7 +24,7 @@
2424
use Symfony\UX\LiveComponent\EventListener\AddLiveAttributesSubscriber;
2525
use Symfony\UX\LiveComponent\EventListener\LiveComponentSubscriber;
2626
use Symfony\UX\LiveComponent\LiveComponentHydrator;
27-
use Symfony\UX\LiveComponent\PropertyHydratorInterface;
27+
use Symfony\UX\LiveComponent\Normalizer\LiveComponentNormalizer;
2828
use Symfony\UX\LiveComponent\Twig\LiveComponentExtension as LiveComponentTwigExtension;
2929
use Symfony\UX\LiveComponent\Twig\LiveComponentRuntime;
3030
use Symfony\UX\TwigComponent\ComponentFactory;
@@ -54,16 +54,14 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
5454
}
5555
);
5656

57-
$container->registerForAutoconfiguration(PropertyHydratorInterface::class)
58-
->addTag('twig.component.property_hydrator')
57+
$container->register('ux.live_component.live_component_normalizer', LiveComponentNormalizer::class)
58+
->setArgument(1, '%kernel.secret%')
59+
->addTag('serializer.normalizer', ['priority' => 100])
60+
->addTag('container.service_subscriber', ['key' => PropertyAccessorInterface::class, 'id' => 'property_accessor'])
5961
;
6062

6163
$container->register('ux.live_component.component_hydrator', LiveComponentHydrator::class)
62-
->setArguments([
63-
new TaggedIteratorArgument('twig.component.property_hydrator'),
64-
new Reference('property_accessor'),
65-
'%kernel.secret%',
66-
])
64+
->setArguments([new Reference('serializer')])
6765
;
6866

6967
$container->register('ux.live_component.event_subscriber', LiveComponentSubscriber::class)

src/LiveComponent/src/Hydrator/DoctrineEntityPropertyHydrator.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/LiveComponent/src/Hydrator/NormalizerBridgePropertyHydrator.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/LiveComponent/src/LiveComponentBundle.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\UX\LiveComponent;
1313

14+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\HttpKernel\Bundle\Bundle;
1617
use Symfony\UX\LiveComponent\DependencyInjection\Compiler\OptionalDependencyPass;
@@ -24,6 +25,7 @@ final class LiveComponentBundle extends Bundle
2425
{
2526
public function build(ContainerBuilder $container): void
2627
{
27-
$container->addCompilerPass(new OptionalDependencyPass());
28+
// must run before Symfony\Component\Serializer\DependencyInjection\SerializerPass
29+
$container->addCompilerPass(new OptionalDependencyPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);
2830
}
2931
}

0 commit comments

Comments
 (0)