Skip to content

Commit

Permalink
Fix deprecations (#38)
Browse files Browse the repository at this point in the history
* Use getObjectManager() instead of getEntityManager()

* Convert Doctrine subscribers to listeners
  • Loading branch information
benr77 authored Jun 14, 2024
1 parent b530a24 commit 316b16e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
16 changes: 2 additions & 14 deletions src/Doctrine/EventSubscriber/PersistDomainEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

namespace Headsnet\DomainEventsBundle\Doctrine\EventSubscriber;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\PersistentCollection;
use Headsnet\DomainEventsBundle\Domain\Model\ContainsEvents;
use Headsnet\DomainEventsBundle\Domain\Model\EventStore;
use Headsnet\DomainEventsBundle\Domain\Model\ReplaceableDomainEvent;

class PersistDomainEventSubscriber implements EventSubscriber
class PersistDomainEventSubscriber
{
private EventStore $eventStore;

Expand All @@ -29,24 +27,14 @@ public function __construct(EventStore $eventStore)
$this->eventStore = $eventStore;
}

/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [
Events::onFlush,
];
}

public function onFlush(OnFlushEventArgs $args): void
{
$this->persistEntityDomainEvents($args);
}

private function persistEntityDomainEvents(OnFlushEventArgs $args): void
{
$uow = $args->getEntityManager()->getUnitOfWork();
$uow = $args->getObjectManager()->getUnitOfWork();

$sources = [
$uow->getScheduledEntityInsertions(),
Expand Down
11 changes: 1 addition & 10 deletions src/Doctrine/EventSubscriber/TableNameEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@

namespace Headsnet\DomainEventsBundle\Doctrine\EventSubscriber;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;

final class TableNameEventSubscriber implements EventSubscriber
final class TableNameEventSubscriber
{
private string $tableName;

Expand All @@ -25,13 +23,6 @@ public function __construct(string $tableName)
$this->tableName = $tableName;
}

public function getSubscribedEvents(): array
{
return [
Events::loadClassMetadata,
];
}

public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
$classMetadata = $eventArgs->getClassMetadata();
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
class="Headsnet\DomainEventsBundle\Doctrine\EventSubscriber\TableNameEventSubscriber"
public="false">
<argument>%headsnet_domain_events.table_name%</argument>
<tag name="doctrine.event_subscriber" connection="default"/>
<tag name="doctrine.event_listener" event="loadClassMetadata" connection="default"/>
</service>

<service id="headsnet_domain_events.event_subscriber.persister"
class="Headsnet\DomainEventsBundle\Doctrine\EventSubscriber\PersistDomainEventSubscriber"
public="false">
<argument type="service" id="headsnet_domain_events.repository.event_store_doctrine"/>
<tag name="doctrine.event_subscriber" connection="default" priority="10"/>
<tag name="doctrine.event_listener" event="onFlush" connection="default" priority="10"/>
</service>

<service id="headsnet_domain_events.repository.event_store_doctrine"
Expand Down

0 comments on commit 316b16e

Please sign in to comment.