diff --git a/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php b/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php index d8a9038..1749c0a 100755 --- a/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php +++ b/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php @@ -6,13 +6,18 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; +use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityManager as DoctrineEntityManager; +use Doctrine\ORM\NativeQuery; use Doctrine\ORM\ORMException; +use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\Query as DqlQuery; use Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration\ObjectHydrator; use Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration\SimpleObjectHydrator; use Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration\DtoHydrator; -class EntityManager extends DoctrineEntityManager implements ToggleableBufferedQueryInterface +class EntityManager extends EntityManagerDecorator implements ToggleableBufferedQueryInterface { public function enableBufferedQuery() { @@ -67,7 +72,30 @@ public static function create($conn, Configuration $config, EventManager $eventM throw new \InvalidArgumentException("Invalid argument: " . $conn); } - return new self($conn, $config, $conn->getEventManager()); + $emRef = new \ReflectionClass( + DoctrineEntityManager::class + ); + /** @var DoctrineEntityManager $em */ + $em = $emRef->newInstanceWithoutConstructor(); + $eventManager = $conn->getEventManager(); + (function () use ($conn, $config, $eventManager) { + $this->__construct($conn, $config, $eventManager); + })->call($em); + + $instance = new self($em); + (function () use ($instance) { + $this->em = $instance; + })->call($instance->getUnitOfWork()); + + return $instance; + } + + /** + * {@inheritDoc} + */ + public function getHydrator($hydrationMode) + { + return $this->newHydrator($hydrationMode); } /** @@ -89,4 +117,39 @@ public function newHydrator($hydrationMode) return parent::newHydrator(...func_get_args()); } } + + /** + * {@inheritDoc} + */ + public function createQuery($dql = '') + { + $query = new DqlQuery($this); + + if (! empty($dql)) { + $query->setDQL($dql); + } + + return $query; + } + + /** + * {@inheritDoc} + */ + public function createNativeQuery($sql, ResultSetMapping $rsm) + { + $query = new NativeQuery($this); + + $query->setSQL($sql); + $query->setResultSetMapping($rsm); + + return $query; + } + + /** + * {@inheritDoc} + */ + public function createQueryBuilder() + { + return new QueryBuilder($this); + } }