From 6a904a2d679100f91f276093fc077bdf0fb78d14 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Fri, 5 Nov 2010 22:13:19 +0100 Subject: [PATCH] DDC-860 - Allow access to EntityManager in loadClassMetadata event --- .../ORM/Event/LoadClassMetadataEventArgs.php | 35 ++++++++++++++++--- .../ORM/Mapping/ClassMetadataFactory.php | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php index 862152a99..15ea0799a 100644 --- a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php @@ -4,6 +4,9 @@ namespace Doctrine\ORM\Event; use Doctrine\Common\EventArgs; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\EntityManager; + /** * Class that holds event arguments for a loadMetadata event. * @@ -12,16 +15,40 @@ use Doctrine\Common\EventArgs; */ class LoadClassMetadataEventArgs extends EventArgs { - private $_classMetadata; + /** + * @var ClassMetadata + */ + private $classMetadata; - public function __construct(\Doctrine\ORM\Mapping\ClassMetadata $classMetadata) + /** + * @var EntityManager + */ + private $em; + + /** + * @param ClassMetadata $classMetadata + * @param EntityManager $em + */ + public function __construct(ClassMetadata $classMetadata, EntityManager $em) { - $this->_classMetadata = $classMetadata; + $this->classMetadata = $classMetadata; + $this->em = $em; } + /** + * @return ClassMetadata + */ public function getClassMetadata() { - return $this->_classMetadata; + return $this->classMetadata; + } + + /** + * @return EntityManager + */ + public function getEntityManager() + { + return $this->em; } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 51994f334..5f1de3883 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -309,7 +309,7 @@ class ClassMetadataFactory $class->setParentClasses($visited); if ($this->evm->hasListeners(Events::loadClassMetadata)) { - $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class); + $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($class, $this->em); $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs); }