Skip to content

Commit

Permalink
DDC-1278 - Clean up event handling of new clear functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Oct 16, 2011
1 parent 22a04fd commit 939fbf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion lib/Doctrine/ORM/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -51,4 +57,24 @@ public function getEntityManager()
{
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;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ public function clear($entityName = null)
}

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));
}
}

Expand Down

0 comments on commit 939fbf9

Please sign in to comment.