From 939fbf9c24f45ea01491bf1dd72921994c7f1656 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 16 Oct 2011 22:45:06 +0200 Subject: [PATCH] DDC-1278 - Clean up event handling of new clear functionality. --- lib/Doctrine/ORM/Event/OnClearEventArgs.php | 28 ++++++++++++++++++++- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Event/OnClearEventArgs.php b/lib/Doctrine/ORM/Event/OnClearEventArgs.php index ad89fbc90..60ce4b3eb 100644 --- a/lib/Doctrine/ORM/Event/OnClearEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnClearEventArgs.php @@ -36,12 +36,18 @@ class OnClearEventArgs extends \Doctrine\Common\EventArgs */ private $em; + /** + * @var string + */ + private $entityClass; + /** * @param \Doctrine\ORM\EntityManager $em */ - public function __construct($em) + public function __construct($em, $entityClass = null) { $this->em = $em; + $this->entityClass = $entityClass; } /** @@ -51,4 +57,24 @@ class OnClearEventArgs extends \Doctrine\Common\EventArgs { return $this->em; } + + /** + * Name of the entity class that is cleared, or empty if all are cleared. + * + * @return string + */ + public function getEntityClass() + { + return $this->entityClass; + } + + /** + * Check if event clears all entities. + * + * @return bool + */ + public function clearsAllEntities() + { + return $this->entityClass === null; + } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 1b291d717..8f5977e5d 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1879,7 +1879,7 @@ class UnitOfWork implements PropertyChangedListener } if ($this->evm->hasListeners(Events::onClear)) { - $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em)); + $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em, $entityName)); } }