Skip to content

Commit

Permalink
Replace deprecated function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusklocke committed Jan 12, 2023
1 parent fe92d46 commit a5cd37e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace HexagonalPlayground\Infrastructure\Persistence\ORM;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostLoadEventArgs;
use Psr\Log\LoggerInterface;
use ReflectionProperty;

Expand All @@ -31,9 +31,9 @@ public function __construct(EntityManager $entityManager, LoggerInterface $logge
$this->logger = $logger;
}

public function postLoad(LifecycleEventArgs $eventArgs)
public function postLoad(PostLoadEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
$entity = $eventArgs->getObject();
$metadata = $this->entityManager->getClassMetadata(get_class($entity));
$properties = array_keys($metadata->embeddedClasses);
foreach ($properties as $property) {
Expand Down
16 changes: 12 additions & 4 deletions src/Infrastructure/Persistence/ORM/DoctrineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace HexagonalPlayground\Infrastructure\Persistence\ORM;

use DI;
use Doctrine\Common\EventManager;
use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
Expand Down Expand Up @@ -49,12 +50,19 @@ public function getDefinitions(): array
{
return [
EntityManagerInterface::class => DI\factory(function (ContainerInterface $container) {
$em = EntityManager::create($container->get(Connection::class), $container->get(Configuration::class));
$em->getEventManager()->addEventListener(
$eventManager = new EventManager();
$entityManager = new EntityManager(
$container->get(Connection::class),
$container->get(Configuration::class),
$eventManager
);

$eventManager->addEventListener(
[Events::postLoad],
new DoctrineEmbeddableListener($em, $container->get(LoggerInterface::class))
new DoctrineEmbeddableListener($entityManager, $container->get(LoggerInterface::class))
);
return $em;

return $entityManager;
}),

Connection::class => DI\factory(function (ContainerInterface $container) {
Expand Down

0 comments on commit a5cd37e

Please sign in to comment.