/**
  * Create a set of audit entities for the entity
  */
 public function createAudit($entity, Entity\RevisionType $revisionType)
 {
     // Entities may be proxy objects
     $found = false;
     foreach ($this->getAuditEntities() as $auditEntityClassName => $auditEntityOptions) {
         if ($entity instanceof $auditEntityClassName) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         // Entity is not audited
         return false;
     }
     $targetEntity = $this->getAuditObjectManager()->getRepository('ZF\\Doctrine\\Audit\\Entity\\TargetEntity')->findOneBy(['name' => get_class($entity)]);
     $revision = $this->getRevision();
     $revisionEntity = new Entity\RevisionEntity();
     $revisionEntity->setRevision($revision);
     $revisionEntity->setRevisionType($revisionType);
     $revisionEntity->setTargetEntity($targetEntity);
     if (method_exists($entity, '__toString')) {
         $revisionEntity->setTitle((string) $entity);
     }
     $auditEntityClass = $targetEntity->getAuditEntity()->getName();
     $auditEntity = new $auditEntityClass();
     $auditEntity->setRevisionEntity($revisionEntity);
     $entityProperties = $this->hydrateAuditEntityFromTargetEntity($auditEntity, $entity);
     foreach ($revisionEntity->getTargetEntity()->getIdentifier() as $identifier) {
         $revisionEntityIdentifierValue = new Entity\RevisionEntityIdentifierValue();
         $revisionEntityIdentifierValue->setRevisionEntity($revisionEntity)->setIdentifier($identifier)->setValue($entityProperties[$identifier->getFieldName()]);
         $this->getAuditObjectManager()->persist($revisionEntityIdentifierValue);
     }
     $this->getAuditObjectManager()->persist($revisionEntity);
     $this->getAuditObjectManager()->persist($auditEntity);
     return $auditEntity;
 }
 private function auditEntity($entity, $revisionType)
 {
     $auditEntities = array();
     $moduleOptions = \ZF\Doctrine\Audit\Module::getModuleOptions();
     if (!in_array(get_class($entity), array_keys($moduleOptions->getAuditedClassNames()))) {
         return array();
     }
     $auditEntityClass = 'ZF\\Doctrine\\Audit\\Entity\\' . str_replace('\\', '_', get_class($entity));
     $auditEntity = new $auditEntityClass();
     $auditEntity->exchangeArray($this->getClassProperties($entity));
     $revisionEntity = new RevisionEntityEntity();
     $revisionEntity->setRevision($this->getRevision());
     $this->getRevision()->getRevisionEntities()->add($revisionEntity);
     $revisionEntity->setRevisionType($revisionType);
     if (method_exists($entity, '__toString')) {
         $revisionEntity->setTitle((string) $entity);
     }
     $this->addRevisionEntity($revisionEntity);
     $revisionEntitySetter = 'set' . $moduleOptions->getRevisionEntityFieldName();
     $auditEntity->{$revisionEntitySetter}($revisionEntity);
     // Re-exchange data after flush to map generated fields
     if ($revisionType == 'INS' or $revisionType == 'UPD') {
         $this->addReexchangeEntity(array('auditEntity' => $auditEntity, 'entity' => $entity, 'revisionEntity' => $revisionEntity));
     } else {
         $revisionEntity->setAuditEntity($auditEntity);
     }
     $auditEntities[] = $auditEntity;
     // Map many to many
     foreach ($this->getClassProperties($entity) as $key => $value) {
         if ($value instanceof PersistentCollection) {
             if (!$this->many2many) {
                 $this->many2many = array();
             }
             $this->many2many[] = array('revisionEntity' => $revisionEntity, 'collection' => $value);
         }
     }
     return $auditEntities;
 }