public function clear($documentName = null)
{
if ($documentName === null) {
$this->identityMap = $this->documentIdentifiers = $this->originalDocumentData = $this->documentChangeSets = $this->documentStates = $this->scheduledForDirtyCheck = $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->collectionUpdates = $this->collectionDeletions = $this->parentAssociations = $this->embeddedDocumentsRegistry = $this->orphanRemovals = $this->hasScheduledCollections = array();
} else {
$visited = array();
foreach ($this->identityMap as $className => $documents) {
if ($className === $documentName) {
foreach ($documents as $document) {
$this->doDetach($document, $visited);
}
}
}
}
if ($this->evm->hasListeners(Events::onClear)) {
$this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->dm, $documentName));
}
}