Files
piratepoet/lib/Doctrine/EntityManagerFactory.php
Jan Jakeš 11b166d018 Use WP timestamp in TimestampListener
[MAILPOET-2014]
2019-07-24 15:03:16 -04:00

40 lines
1.1 KiB
PHP

<?php
namespace MailPoet\Doctrine;
use MailPoet\Doctrine\EventListeners\TimestampListener;
use MailPoetVendor\Doctrine\DBAL\Connection;
use MailPoetVendor\Doctrine\ORM\Configuration;
use MailPoetVendor\Doctrine\ORM\EntityManager;
use MailPoetVendor\Doctrine\ORM\Events;
class EntityManagerFactory {
/** @var Connection */
private $connection;
/** @var Configuration */
private $configuration;
private $timestamp_listener;
function __construct(Connection $connection, Configuration $configuration, TimestampListener $timestamp_listener) {
$this->connection = $connection;
$this->configuration = $configuration;
$this->timestamp_listener = $timestamp_listener;
}
function createEntityManager() {
$entity_manager = EntityManager::create($this->connection, $this->configuration);
$this->setupTimestampListener($entity_manager);
return $entity_manager;
}
private function setupTimestampListener(EntityManager $entity_manager) {
$entity_manager->getEventManager()->addEventListener(
[Events::prePersist, Events::preUpdate],
$this->timestamp_listener
);
}
}