From fa7799cec155b501e610ff0f941cf9eb4053cce5 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 8 Jun 2016 12:24:41 +0300 Subject: [PATCH] return check EventManager --- lib/Doctrine/ORM/EntityManager.php | 5 +++++ lib/Doctrine/ORM/ORMException.php | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 97aab4f81..c889f90c2 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -851,6 +851,7 @@ use Doctrine\Common\Util\ClassUtils; * @return Connection * * @throws \InvalidArgumentException + * @throws ORMException */ protected static function createConnection($connection, Configuration $config, EventManager $eventManager = null) { @@ -862,6 +863,10 @@ use Doctrine\Common\Util\ClassUtils; throw new \InvalidArgumentException("Invalid argument: " . $connection); } + if ($eventManager !== null && $connection->getEventManager() !== $eventManager) { + throw ORMException::mismatchedEventManager(); + } + return $connection; } diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 286eb26e8..6d8a6d631 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -154,6 +154,14 @@ class ORMException extends Exception return new self("'$mode' is an invalid hydration mode."); } + /** + * @return ORMException + */ + public static function mismatchedEventManager() + { + return new self("Cannot use different EventManager instances for EntityManager and Connection."); + } + /** * @param string $methodName *