Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Symfony\UX\LiveComponent\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\UX\LiveComponent\Hydrator\DoctrineEntityPropertyHydrator;
use Symfony\UX\LiveComponent\Hydrator\NormalizerBridgePropertyHydrator;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class OptionalDependencyPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if ($container->hasDefinition('doctrine')) {
$container->register('ux.live_component.doctrine_entity_property_hydrator', DoctrineEntityPropertyHydrator::class)
->setArguments([[new Reference('doctrine')]])
->addTag('twig.component.property_hydrator', ['priority' => -100])
;
}

if ($container->hasDefinition('serializer')) {
$container->register('ux.live_component.serializer_property_hydrator', NormalizerBridgePropertyHydrator::class)
->setArguments([new Reference('serializer')])
->addTag('twig.component.property_hydrator', ['priority' => -200])
;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
use Symfony\UX\LiveComponent\ComponentValidator;
use Symfony\UX\LiveComponent\ComponentValidatorInterface;
use Symfony\UX\LiveComponent\EventListener\LiveComponentSubscriber;
use Symfony\UX\LiveComponent\Hydrator\DoctrineEntityPropertyHydrator;
use Symfony\UX\LiveComponent\Hydrator\NormalizerBridgePropertyHydrator;
use Symfony\UX\LiveComponent\LiveComponentHydrator;
use Symfony\UX\LiveComponent\PropertyHydratorInterface;
use Symfony\UX\LiveComponent\Twig\LiveComponentExtension as LiveComponentTwigExtension;
Expand Down Expand Up @@ -60,16 +58,6 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
->addTag('twig.component.property_hydrator')
;

$container->register('ux.live_component.doctrine_entity_property_hydrator', DoctrineEntityPropertyHydrator::class)
->setArguments([[new Reference('doctrine')]])
->addTag('twig.component.property_hydrator', ['priority' => -100])
;

$container->register('ux.live_component.serializer_property_hydrator', NormalizerBridgePropertyHydrator::class)
->setArguments([new Reference('serializer')])
->addTag('twig.component.property_hydrator', ['priority' => -200])
;

$container->register('ux.live_component.component_hydrator', LiveComponentHydrator::class)
->setArguments([
new TaggedIteratorArgument('twig.component.property_hydrator'),
Expand Down
6 changes: 6 additions & 0 deletions src/LiveComponent/src/LiveComponentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Symfony\UX\LiveComponent;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\UX\LiveComponent\DependencyInjection\Compiler\OptionalDependencyPass;

/**
* @author Kevin Bond <kevinbond@gmail.com>
Expand All @@ -20,4 +22,8 @@
*/
final class LiveComponentBundle extends Bundle
{
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new OptionalDependencyPass());
}
}