Skip to content

Commit

Permalink
[Messenger] Support DoctrineMessageBusHook for Doctrine ODM
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Jan 2, 2024
1 parent 046b885 commit 1897ec3
Show file tree
Hide file tree
Showing 21 changed files with 29 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
use Draw\Bundle\UserBundle\Security\TwoFactorAuthentication\Entity\TwoFactorAuthenticationUserInterface;
use Draw\Component\EntityMigrator\MigrationTargetEntityInterface;
use Draw\Component\Mailer\Recipient\LocalizationAwareInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;
use Draw\DoctrineExtra\Common\Collections\CollectionUtil;
use JMS\Serializer\Annotation as Serializer;
use Ramsey\Uuid\Uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Draw\Component\Messenger\DoctrineMessageBusHook\EnvelopeFactory;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Event\EnvelopeCreatedEvent;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Draw\Component\Messenger\DoctrineMessageBusHook\EnvelopeFactory;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Symfony\Component\Messenger\Envelope;

interface EnvelopeFactoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Draw\Component\Messenger\DoctrineMessageBusHook\Event;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Contracts\EventDispatcher\Event;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Draw\Component\Messenger\DoctrineMessageBusHook\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnClearEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\OnClearEventArgs;
use Doctrine\Persistence\Proxy;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\EnvelopeFactory\EnvelopeFactoryInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Message\LifeCycleAwareMessageInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\Service\ResetInterface;

Expand Down Expand Up @@ -72,9 +71,6 @@ public function postFlush(): void
}
}

/**
* @param LifecycleEventArgs<EntityManagerInterface> $event
*/
private function trackMessageHolder(LifecycleEventArgs $event): void
{
$entity = $event->getObject();
Expand All @@ -86,7 +82,11 @@ private function trackMessageHolder(LifecycleEventArgs $event): void
$entityManager = $event->getObjectManager();

$classMetadata = $entityManager->getClassMetadata($entity::class);
$className = $classMetadata->rootEntityName;

$className = $classMetadata->rootDocumentName
?? $classMetadata->rootEntityName
?? $classMetadata->getName();

$this->messageHolders[$className][spl_object_id($entity)] = $entity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Draw\Component\Messenger\DoctrineMessageBusHook\Message;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;

interface LifeCycleAwareMessageInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Draw\Component\Messenger\DoctrineMessageBusHook\Entity;
namespace Draw\Component\Messenger\DoctrineMessageBusHook\Model;

interface MessageHolderInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Draw\Component\Messenger\DoctrineMessageBusHook\Entity;
namespace Draw\Component\Messenger\DoctrineMessageBusHook\Model;

trait MessageHolderTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Draw\Component\Messenger\Tests\DoctrineMessageBusHook\Entity;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Draw\Component\Messenger\Tests\DoctrineMessageBusHook\EnvelopeFactory;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\EnvelopeFactory\BasicEnvelopeFactory;
use Draw\Component\Messenger\DoctrineMessageBusHook\Event\EnvelopeCreatedEvent;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Draw\Component\Tester\MockTrait;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Draw\Component\Messenger\Tests\DoctrineMessageBusHook\Event;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Event\EnvelopeCreatedEvent;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\Persistence\Proxy;
use Draw\Component\Core\Reflection\ReflectionAccessor;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\EnvelopeFactory\EnvelopeFactoryInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\EventListener\DoctrineBusMessageListener;
use Draw\Component\Messenger\DoctrineMessageBusHook\Message\LifeCycleAwareMessageInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Draw\Component\Tester\MockTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Draw\Component\Messenger\Tests\DoctrineMessageBusHook\EventListener;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Event\EnvelopeCreatedEvent;
use Draw\Component\Messenger\DoctrineMessageBusHook\EventListener\EnvelopeFactoryDelayStampListener;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Draw\Component\Messenger\Tests\DoctrineMessageBusHook\EventListener;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Event\EnvelopeCreatedEvent;
use Draw\Component\Messenger\DoctrineMessageBusHook\EventListener\EnvelopeFactoryDispatchAfterCurrentBusStampListener;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down
3 changes: 1 addition & 2 deletions packages/user-bundle/Entity/LockableUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Doctrine\ORM\Mapping as ORM;
use Draw\Bundle\UserBundle\Message\NewUserLockMessage;
use Draw\Bundle\UserBundle\Message\TemporaryUnlockedMessage;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;

use function Draw\Component\Core\use_trait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Doctrine\ORM\Mapping as ORM;
use Draw\Bundle\UserBundle\Message\NewUserMessage;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;

use function Draw\Component\Core\use_trait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Doctrine\ORM\Mapping as ORM;
use Draw\Bundle\UserBundle\Message\PasswordChangeRequestedMessage;

use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;

use function Draw\Component\Core\use_trait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Draw\Bundle\UserBundle\Message;

use Draw\Bundle\UserBundle\Entity\PasswordChangeUserInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Message\LifeCycleAwareMessageInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;

class PasswordChangeRequestedMessage implements LifeCycleAwareMessageInterface
{
Expand Down
2 changes: 1 addition & 1 deletion packages/user-bundle/Message/TemporaryUnlockedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Draw\Bundle\UserBundle\Entity\LockableUserInterface;
use Draw\Component\Core\DateTimeUtils;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Message\LifeCycleAwareMessageInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;

class TemporaryUnlockedMessage implements LifeCycleAwareMessageInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Draw\Bundle\UserBundle\Entity\SecurityUserTrait;
use Draw\Bundle\UserBundle\Entity\UserLock;
use Draw\Bundle\UserBundle\Message\TemporaryUnlockedMessage;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Draw\Bundle\UserBundle\Entity\LockableUserTrait;
use Draw\Bundle\UserBundle\Entity\SecurityUserTrait;
use Draw\Bundle\UserBundle\Message\TemporaryUnlockedMessage;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Entity\MessageHolderTrait;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderInterface;
use Draw\Component\Messenger\DoctrineMessageBusHook\Model\MessageHolderTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

Expand Down

0 comments on commit 1897ec3

Please sign in to comment.