-
-
Notifications
You must be signed in to change notification settings - Fork 357
[Turbo] Fix broadcast with composite primary key #1857
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
base: 2.x
Are you sure you want to change the base?
Conversation
d868350
to
cba61dc
Compare
if (!isset($this->broadcastedClasses[$entityClass])) { | ||
$this->broadcastedClasses[$entityClass] = []; | ||
$r = new \ReflectionClass($entityClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is worth the change.
if ('createdEntities' !== $property) { | ||
$id = $em->getClassMetadata($class)->getIdentifierValues($entity); | ||
$id = $this->doctrineIdAccessor->getEntityId($entity, $em); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you illustrate precisely what cannot be done before, what it would look like, and same after your changes ? :)
if (!$this->doctrine) { | ||
return $class; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if $em is passed ?
private $doctrine; | ||
|
||
public function __construct(?ManagerRegistry $doctrine = null) | ||
{ | ||
$this->doctrine = $doctrine; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ppp there please
$values = $em->getClassMetadata($entity::class)->getIdentifierValues($entity); | ||
|
||
foreach ($values as $key => $value) { | ||
if (\is_object($value)) { | ||
$values[$key] = $this->getIdentifierValues($em, $value); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some doc/example here ?
$container->addCompilerPass(new class() implements CompilerPassInterface { | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$serviceIds = [ | ||
...$container->findTaggedServiceIds('turbo.broadcaster'), | ||
...$container->findTaggedServiceIds('turbo.renderer.stream_listen'), | ||
]; | ||
|
||
foreach ($serviceIds as $serviceId => $tags) { | ||
$definition = $container->getDefinition($serviceId); | ||
|
||
$definition | ||
->addArgument(new Reference('turbo.id_formatter')) | ||
->addArgument(new Reference('turbo.doctrine_class_resolver')); | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tags refer to BroadcasterInterface and TurboStreamListenRendererInterface services, so you cannot add those arguments there as it would potentially impact other services which don't use them.
Kind of a feature as it adds support for using broadcast with entities using a composite primary key.
IdAccessor
into anotherDoctrineIdAccessor
to prevent duplicated codeIdFormatter
to format the values returned from the doctrine functiongetIdentifierValues
DoctrineClassResolver
to resolve real entity class names. (Doctrine;Proxy)Others
CONTRIBUTING.md
Song.php
)Last workflow issue with phpstan is fixed in #1854
Fixed more than I wanted, a bit unsure about the injection of services into
Broadcaster
in the Mercure integration, was even confused that the turbo services for the Mercure integration are registered in the MercureBundle.