Ver código fonte

[Mapping] remove duplicated identifier extractor, update interface of eventarg adapter

gedi 13 anos atrás
pai
commit
553fb4cdb4

+ 1 - 1
lib/Gedmo/Loggable/Document/Repository/LogEntryRepository.php

@@ -90,7 +90,7 @@ class LogEntryRepository extends DocumentRepository
                         if (in_array($field, $fields)) {
                             if ($objectMeta->isSingleValuedAssociation($field)) {
                                 $mapping = $objectMeta->getFieldMapping($field);
-                                $value = $value ? $this->dm->getReference($mapping['targetDocument'], current($value)) : null;
+                                $value = $value ? $this->dm->getReference($mapping['targetDocument'], $value) : null;
                             }
                             $wrapped->setPropertyValue($field, $value);
                             unset($fields[array_search($field, $fields)]);

+ 17 - 15
lib/Gedmo/Loggable/LoggableListener.php

@@ -2,10 +2,11 @@
 
 namespace Gedmo\Loggable;
 
-use Doctrine\Common\Persistence\ObjectManager,
-    Gedmo\Mapping\MappedEventSubscriber,
-    Gedmo\Loggable\Mapping\Event\LoggableAdapter,
-    Doctrine\Common\EventArgs;
+use Doctrine\Common\EventArgs;
+use Doctrine\Common\Persistence\ObjectManager;
+use Gedmo\Mapping\MappedEventSubscriber;
+use Gedmo\Loggable\Mapping\Event\LoggableAdapter;
+use Gedmo\Tool\Wrapper\AbstractWrapper;
 
 /**
  * Loggable listener
@@ -129,14 +130,14 @@ class LoggableListener extends MappedEventSubscriber
         $oid = spl_object_hash($object);
         $uow = $om->getUnitOfWork();
         if ($this->pendingLogEntryInserts && array_key_exists($oid, $this->pendingLogEntryInserts)) {
-            $meta = $om->getClassMetadata(get_class($object));
+            $wrapped = AbstractWrapper::wrapp($object, $om);
+            $meta = $wrapped->getMetadata();
             $config = $this->getConfiguration($om, $meta->name);
-            // there should be single identifier
-            $identifierField = $ea->getSingleIdentifierFieldName($meta);
+
             $logEntry = $this->pendingLogEntryInserts[$oid];
             $logEntryMeta = $om->getClassMetadata(get_class($logEntry));
 
-            $id = $meta->getReflectionProperty($identifierField)->getValue($object);
+            $id = $wrapped->getIdentifier();
             $logEntryMeta->getReflectionProperty('objectId')->setValue($logEntry, $id);
             $uow->scheduleExtraUpdate($logEntry, array(
                 'objectId' => array(null, $id)
@@ -145,7 +146,8 @@ class LoggableListener extends MappedEventSubscriber
             unset($this->pendingLogEntryInserts[$oid]);
         }
         if ($this->pendingRelatedObjects && array_key_exists($oid, $this->pendingRelatedObjects)) {
-            $identifiers = $ea->extractIdentifier($om, $object, false);
+            $wrapped = AbstractWrapper::wrapp($object, $om);
+            $identifiers = $wrapped->getIdentifier(false);
             foreach ($this->pendingRelatedObjects[$oid] as $props) {
                 $logEntry = $props['log'];
                 $logEntryMeta = $om->getClassMetadata(get_class($logEntry));
@@ -153,7 +155,6 @@ class LoggableListener extends MappedEventSubscriber
                 $data[$props['field']] = $identifiers;
                 $logEntry->setData($data);
 
-
                 $uow->scheduleExtraUpdate($logEntry, array(
                     'data' => array($oldData, $data)
                 ));
@@ -218,7 +219,8 @@ class LoggableListener extends MappedEventSubscriber
     private function createLogEntry($action, $object, LoggableAdapter $ea)
     {
         $om = $ea->getObjectManager();
-        $meta = $om->getClassMetadata(get_class($object));
+        $wrapped = AbstractWrapper::wrapp($object, $om);
+        $meta = $wrapped->getMetadata();
         if ($config = $this->getConfiguration($om, $meta->name)) {
             $logEntryClass = $this->getLogEntryClass($ea, $meta->name);
             $logEntry = new $logEntryClass;
@@ -229,8 +231,7 @@ class LoggableListener extends MappedEventSubscriber
             $logEntry->setLoggedAt();
 
             // check for the availability of the primary key
-            $identifierField = $ea->getSingleIdentifierFieldName($meta);
-            $objectId = $meta->getReflectionProperty($identifierField)->getValue($object);
+            $objectId = $wrapped->getIdentifier();
             if (!$objectId && $action === self::ACTION_CREATE) {
                 $this->pendingLogEntryInserts[spl_object_hash($object)] = $logEntry;
             }
@@ -245,8 +246,9 @@ class LoggableListener extends MappedEventSubscriber
                     $value = $changes[1];
                     if ($meta->isSingleValuedAssociation($field) && $value) {
                         $oid = spl_object_hash($value);
-                        $value = $ea->extractIdentifier($om, $value, false);
-                        if (!is_array($value)) {
+                        $wrappedAssoc = AbstractWrapper::wrapp($value, $om);
+                        $value = $wrappedAssoc->getIdentifier(false);
+                        if (!is_array($value) && !$value) {
                             $this->pendingRelatedObjects[$oid][] = array(
                                 'log' => $logEntry,
                                 'field' => $field

+ 40 - 72
lib/Gedmo/Mapping/Event/Adapter/ODM.php

@@ -3,11 +3,9 @@
 namespace Gedmo\Mapping\Event\Adapter;
 
 use Gedmo\Mapping\Event\AdapterInterface;
+use Gedmo\Exception\RuntimeException;
 use Doctrine\Common\EventArgs;
-use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo;
-use Doctrine\ODM\MongoDB\UnitOfWork;
 use Doctrine\ODM\MongoDB\DocumentManager;
-use Doctrine\ODM\MongoDB\Proxy\Proxy;
 
 /**
  * Doctrine event adapter for ODM specific
@@ -22,10 +20,15 @@ use Doctrine\ODM\MongoDB\Proxy\Proxy;
 class ODM implements AdapterInterface
 {
     /**
-     * @var EventArgs
+     * @var \Doctrine\Common\EventArgs
      */
     private $args;
 
+    /**
+     * @var \Doctrine\ODM\MongoDB\DocumentManager
+     */
+    private $dm;
+
     /**
      * {@inheritdoc}
      */
@@ -51,133 +54,98 @@ class ODM implements AdapterInterface
     }
 
     /**
-     * Extracts identifiers from object or proxy
+     * Set the document manager
      *
-     * @param DocumentManager $dm
-     * @param object $object
-     * @param bool $single
-     * @return mixed - array or single identifier
+     * @param \Doctrine\ODM\MongoDB\DocumentManager $dm
      */
-    public function extractIdentifier(DocumentManager $dm, $object, $single = true)
+    public function setDocumentManager(DocumentManager $dm)
     {
-        $meta = $dm->getClassMetadata(get_class($object));
-        if ($object instanceof Proxy) {
-            $id = $dm->getUnitOfWork()->getDocumentIdentifier($object);
-        } else {
-            $id = $meta->getReflectionProperty($meta->identifier)->getValue($object);
-        }
+        $this->dm = $dm;
+    }
 
-        if ($single || !$id) {
-            return $id;
-        } else {
-            return array($meta->identifier => $id);
+    /**
+     * {@inheritdoc}
+     */
+    public function getObjectManager()
+    {
+        if (!is_null($this->dm)) {
+            return $this->dm;
         }
+        return $this->__call('getDocumentManager', array());
     }
 
     /**
-     * Call event specific method
-     *
-     * @param string $method
-     * @param array $args
-     * @return mixed
+     * {@inheritdoc}
      */
     public function __call($method, $args)
     {
+        if (is_null($this->args)) {
+            throw new RuntimeException("Event args must be set before calling its methods");
+        }
         $method = str_replace('Object', $this->getDomainObjectName(), $method);
         return call_user_func_array(array($this->args, $method), $args);
     }
 
     /**
-     * Get the object changeset from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @param Object $object
-     * @return array
+     * {@inheritdoc}
      */
-    public function getObjectChangeSet(UnitOfWork $uow, $object)
+    public function getObjectChangeSet($uow, $object)
     {
         return $uow->getDocumentChangeSet($object);
     }
 
     /**
-     * Get the single identifier field name
-     *
-     * @param ClassMetadataInfo $meta
-     * @throws MappingException - if identifier is composite
-     * @return string
+     * {@inheritdoc}
      */
-    public function getSingleIdentifierFieldName(ClassMetadataInfo $meta)
+    public function getSingleIdentifierFieldName($meta)
     {
         return $meta->identifier;
     }
 
     /**
-     * Recompute the single object changeset from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @param ClassMetadataInfo $meta
-     * @param Object $object
-     * @return void
+     * {@inheritdoc}
      */
-    public function recomputeSingleObjectChangeSet(UnitOfWork $uow, ClassMetadataInfo $meta, $object)
+    public function recomputeSingleObjectChangeSet($uow, $meta, $object)
     {
         $uow->recomputeSingleDocumentChangeSet($meta, $object);
     }
 
     /**
-     * Get the scheduled object updates from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @return array
+     * {@inheritdoc}
      */
-    public function getScheduledObjectUpdates(UnitOfWork $uow)
+    public function getScheduledObjectUpdates($uow)
     {
         return $uow->getScheduledDocumentUpdates();
     }
 
     /**
-     * Get the scheduled object insertions from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @return array
+     * {@inheritdoc}
      */
-    public function getScheduledObjectInsertions(UnitOfWork $uow)
+    public function getScheduledObjectInsertions($uow)
     {
         return $uow->getScheduledDocumentInsertions();
     }
 
     /**
-     * Get the scheduled object deletions from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @return array
+     * {@inheritdoc}
      */
-    public function getScheduledObjectDeletions(UnitOfWork $uow)
+    public function getScheduledObjectDeletions($uow)
     {
         return $uow->getScheduledDocumentDeletions();
     }
 
     /**
-     * Sets a property value of the original data array of an object
-     *
-     * @param UnitOfWork $uow
-     * @param string $oid
-     * @param string $property
-     * @param mixed $value
-     * @return void
+     * {@inheritdoc}
      */
-    public function setOriginalObjectProperty(UnitOfWork $uow, $oid, $property, $value)
+    public function setOriginalObjectProperty($uow, $oid, $property, $value)
     {
         $uow->setOriginalDocumentProperty($oid, $property, $value);
     }
 
     /**
-     * Clears the property changeset of the object with the given OID.
-     *
-     * @param UnitOfWork $uow
-     * @param string $oid The object's OID.
+     * {@inheritdoc}
      */
-    public function clearObjectChangeSet(UnitOfWork $uow, $oid)
+    public function clearObjectChangeSet($uow, $oid)
     {
         $uow->clearDocumentChangeSet($oid);
     }

+ 44 - 82
lib/Gedmo/Mapping/Event/Adapter/ORM.php

@@ -3,11 +3,9 @@
 namespace Gedmo\Mapping\Event\Adapter;
 
 use Gedmo\Mapping\Event\AdapterInterface;
+use Gedmo\Exception\RuntimeException;
 use Doctrine\Common\EventArgs;
-use Doctrine\ORM\Mapping\ClassMetadataInfo;
-use Doctrine\ORM\UnitOfWork;
 use Doctrine\ORM\EntityManager;
-use Doctrine\ORM\Proxy\Proxy;
 
 /**
  * Doctrine event adapter for ORM specific
@@ -22,10 +20,15 @@ use Doctrine\ORM\Proxy\Proxy;
 class ORM implements AdapterInterface
 {
     /**
-     * @var EventArgs
+     * @var \Doctrine\Common\EventArgs
      */
     private $args;
 
+    /**
+     * @var \Doctrine\ORM\EntityManager
+     */
+    private $em;
+
     /**
      * {@inheritdoc}
      */
@@ -51,139 +54,98 @@ class ORM implements AdapterInterface
     }
 
     /**
-     * Extracts identifiers from object or proxy
-     *
-     * @param EntityManager $em
-     * @param object $object
-     * @param bool $single
-     * @return mixed - array or single identifier
+     * {@inheritdoc}
      */
-    public function extractIdentifier(EntityManager $em, $object, $single = true)
+    public function __call($method, $args)
     {
-        if ($object instanceof Proxy) {
-            $id = $em->getUnitOfWork()->getEntityIdentifier($object);
-        } else {
-            $meta = $em->getClassMetadata(get_class($object));
-            $id = array();
-            foreach ($meta->identifier as $name) {
-                $id[$name] = $meta->getReflectionProperty($name)->getValue($object);
-                // return null if one of identifiers is missing
-                if (!$id[$name]) {
-                    return null;
-                }
-            }
-        }
-
-        if ($single) {
-            $id = current($id);
+        if (is_null($this->args)) {
+            throw new RuntimeException("Event args must be set before calling its methods");
         }
-        return $id;
+        $method = str_replace('Object', $this->getDomainObjectName(), $method);
+        return call_user_func_array(array($this->args, $method), $args);
     }
 
     /**
-     * Call event specific method
+     * Set the entity manager
      *
-     * @param string $method
-     * @param array $args
-     * @return mixed
+     * @param \Doctrine\ORM\EntityManager $em
      */
-    public function __call($method, $args)
+    public function setEntityManager(EntityManager $em)
     {
-        $method = str_replace('Object', $this->getDomainObjectName(), $method);
-        return call_user_func_array(array($this->args, $method), $args);
+        $this->em = $em;
     }
 
     /**
-     * Get the object changeset from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @param Object $object
-     * @return array
+     * {@inheritdoc}
+     */
+    public function getObjectManager()
+    {
+        if (!is_null($this->em)) {
+            return $this->em;
+        }
+        return $this->__call('getEntityManager', array());
+    }
+
+    /**
+     * {@inheritdoc}
      */
-    public function getObjectChangeSet(UnitOfWork $uow, $object)
+    public function getObjectChangeSet($uow, $object)
     {
         return $uow->getEntityChangeSet($object);
     }
 
     /**
-     * Get the single identifier field name
-     *
-     * @param ClassMetadataInfo $meta
-     * @throws MappingException - if identifier is composite
-     * @return string
+     * {@inheritdoc}
      */
-    public function getSingleIdentifierFieldName(ClassMetadataInfo $meta)
+    public function getSingleIdentifierFieldName($meta)
     {
         return $meta->getSingleIdentifierFieldName();
     }
 
     /**
-     * Recompute the single object changeset from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @param ClassMetadataInfo $meta
-     * @param Object $object
-     * @return void
+     * {@inheritdoc}
      */
-    public function recomputeSingleObjectChangeSet(UnitOfWork $uow, ClassMetadataInfo $meta, $object)
+    public function recomputeSingleObjectChangeSet($uow, $meta, $object)
     {
         $uow->recomputeSingleEntityChangeSet($meta, $object);
     }
 
     /**
-     * Get the scheduled object updates from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @return array
+     * {@inheritdoc}
      */
-    public function getScheduledObjectUpdates(UnitOfWork $uow)
+    public function getScheduledObjectUpdates($uow)
     {
         return $uow->getScheduledEntityUpdates();
     }
 
     /**
-     * Get the scheduled object insertions from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @return array
+     * {@inheritdoc}
      */
-    public function getScheduledObjectInsertions(UnitOfWork $uow)
+    public function getScheduledObjectInsertions($uow)
     {
         return $uow->getScheduledEntityInsertions();
     }
 
     /**
-     * Get the scheduled object deletions from a UnitOfWork
-     *
-     * @param UnitOfWork $uow
-     * @return array
+     * {@inheritdoc}
      */
-    public function getScheduledObjectDeletions(UnitOfWork $uow)
+    public function getScheduledObjectDeletions($uow)
     {
         return $uow->getScheduledEntityDeletions();
     }
 
     /**
-     * Sets a property value of the original data array of an object
-     *
-     * @param UnitOfWork $uow
-     * @param string $oid
-     * @param string $property
-     * @param mixed $value
-     * @return void
+     * {@inheritdoc}
      */
-    public function setOriginalObjectProperty(UnitOfWork $uow, $oid, $property, $value)
+    public function setOriginalObjectProperty($uow, $oid, $property, $value)
     {
         $uow->setOriginalEntityProperty($oid, $property, $value);
     }
 
     /**
-     * Clears the property changeset of the object with the given OID.
-     *
-     * @param UnitOfWork $uow
-     * @param string $oid The object's OID.
+     * {@inheritdoc}
      */
-    public function clearObjectChangeSet(UnitOfWork $uow, $oid)
+    public function clearObjectChangeSet($uow, $oid)
     {
         $uow->clearEntityChangeSet($oid);
     }

+ 89 - 1
lib/Gedmo/Mapping/Event/AdapterInterface.php

@@ -20,10 +20,19 @@ interface AdapterInterface
     /**
      * Set the eventargs
      *
-     * @param EventArgs $args
+     * @param \Doctrine\Common\EventArgs $args
      */
     function setEventArgs(EventArgs $args);
 
+    /**
+     * Call specific method on event args
+     *
+     * @param string $method
+     * @param array $args
+     * @return mixed
+     */
+    function __call($method, $args);
+
     /**
      * Get the name of domain object
      *
@@ -34,6 +43,85 @@ interface AdapterInterface
     /**
      * Get the name of used manager for this
      * event adapter
+     *
+     * @return string
      */
     function getManagerName();
+
+    /**
+     * Get used object manager
+     *
+     * @return \Doctrine\Common\Persistence\ObjectManager
+     */
+    function getObjectManager();
+
+    /**
+     * Get the object changeset from a UnitOfWork
+     *
+     * @param UnitOfWork $uow
+     * @param Object $object
+     * @return array
+     */
+    function getObjectChangeSet($uow, $object);
+
+    /**
+     * Get the single identifier field name
+     *
+     * @param ClassMetadata $meta
+     * @return string
+     */
+    function getSingleIdentifierFieldName($meta);
+
+    /**
+     * Recompute the single object changeset from a UnitOfWork
+     *
+     * @param UnitOfWork $uow
+     * @param ClassMetadata $meta
+     * @param Object $object
+     * @return void
+     */
+    function recomputeSingleObjectChangeSet($uow, $meta, $object);
+
+    /**
+     * Get the scheduled object updates from a UnitOfWork
+     *
+     * @param UnitOfWork $uow
+     * @return array
+     */
+    function getScheduledObjectUpdates($uow);
+
+    /**
+     * Get the scheduled object insertions from a UnitOfWork
+     *
+     * @param UnitOfWork $uow
+     * @return array
+     */
+    function getScheduledObjectInsertions($uow);
+
+    /**
+     * Get the scheduled object deletions from a UnitOfWork
+     *
+     * @param UnitOfWork $uow
+     * @return array
+     */
+    function getScheduledObjectDeletions($uow);
+
+    /**
+     * Sets a property value of the original data array of an object
+     *
+     * @param UnitOfWork $uow
+     * @param string $oid
+     * @param string $property
+     * @param mixed $value
+     * @return void
+     */
+    function setOriginalObjectProperty($uow, $oid, $property, $value);
+
+    /**
+     * Clears the property changeset of the object with the given OID.
+     *
+     * @param UnitOfWork $uow
+     * @param string $oid The object's OID.
+     */
+    function clearObjectChangeSet($uow, $oid);
 }

+ 2 - 2
lib/Gedmo/Sluggable/Mapping/Event/Adapter/ODM.php

@@ -25,9 +25,9 @@ final class ODM extends BaseAdapterODM implements SluggableAdapter
     public function getSimilarSlugs($object, $meta, array $config, $slug)
     {
         $dm = $this->getObjectManager();
+        $wrapped = AbstractWrapper::wrapp($object, $dm);
         $qb = $dm->createQueryBuilder($config['useObjectClass']);
-        $identifier = $this->extractIdentifier($dm, $object);
-        if ($identifier && !$meta->isIdentifier($config['slug'])) {
+        if (($identifier = $wrapped->getIdentifier()) && !$meta->isIdentifier($config['slug'])) {
             $qb->field($meta->identifier)->notEqual($identifier);
         }
         $qb->field($config['slug'])->equals(new \MongoRegex('/^' . preg_quote($slug, '/') . '/'));

+ 7 - 9
lib/Gedmo/Sluggable/Mapping/Event/Adapter/ORM.php

@@ -2,9 +2,10 @@
 
 namespace Gedmo\Sluggable\Mapping\Event\Adapter;
 
-use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
 use Doctrine\ORM\Query;
+use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
 use Gedmo\Sluggable\Mapping\Event\SluggableAdapter;
+use Gedmo\Tool\Wrapper\AbstractWrapper;
 
 /**
  * Doctrine event adapter for ORM adapted
@@ -24,26 +25,23 @@ final class ORM extends BaseAdapterORM implements SluggableAdapter
     public function getSimilarSlugs($object, $meta, array $config, $slug)
     {
         $em = $this->getObjectManager();
+        $wrapped = AbstractWrapper::wrapp($object, $em);
         $qb = $em->createQueryBuilder();
         $qb->select('rec.' . $config['slug'])
             ->from($config['useObjectClass'], 'rec')
             ->where($qb->expr()->like(
                 'rec.' . $config['slug'],
                 $qb->expr()->literal($slug . '%'))
-            );
+            )
+        ;
         // include identifiers
-        $entityIdentifiers = $this->extractIdentifier($em, $object, false);
-        $parameters = array();
-        foreach ((array)$entityIdentifiers as $field => $value) {
+        foreach ((array)$wrapped->getIdentifier(false) as $field => $value) {
             if (strlen($value) && !$meta->isIdentifier($config['slug'])) {
                 $qb->andWhere('rec.' . $field . ' <> :' . $field);
-                $parameters[$field] = $value;
+                $qb->setParameter($field, $value);
             }
         }
         $q = $qb->getQuery();
-        if ($parameters) {
-            $q->setParameters($parameters);
-        }
         $q->setHydrationMode(Query::HYDRATE_ARRAY);
         return $q->execute();
     }

+ 7 - 29
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -9,6 +9,7 @@ use Doctrine\ORM\EntityManager;
 use Doctrine\ORM\Proxy\Proxy;
 use Gedmo\Tree\TreeListener;
 use Doctrine\ORM\Version;
+use Gedmo\Tool\Wrapper\AbstractWrapper;
 
 /**
  * This strategy makes tree act like
@@ -260,12 +261,13 @@ class Closure implements Strategy
      */
     public function updateNode(EntityManager $em, $node, $oldParent)
     {
-        $meta = $em->getClassMetadata(get_class($node));
+        $wrapped = AbstractWrapper::wrapp($node, $em);
+        $meta = $wrapped->getMetadata();
         $config = $this->listener->getConfiguration($em, $meta->name);
         $closureMeta = $em->getClassMetadata($config['closure']);
 
-        $nodeId = $this->extractIdentifier($em, $node);
-        $parent = $meta->getReflectionProperty($config['parent'])->getValue($node);
+        $nodeId = $wrapped->getIdentifier();
+        $parent = $wrapped->getPropertyValue($config['parent']);
         $table = $closureMeta->getTableName();
         $conn = $em->getConnection();
         // ensure integrity
@@ -298,7 +300,8 @@ class Closure implements Strategy
             }
         }
         if ($parent) {
-            $parentId = $this->extractIdentifier($em, $parent);
+            $wrappedParent = AbstractWrapper::wrapp($parent, $em);
+            $parentId = $wrappedParent->getIdentifier();
             $query = "SELECT c1.ancestor, c2.descendant, (c1.depth + c2.depth + 1) AS depth";
             $query .= " FROM {$table} c1, {$table} c2";
             $query .= " WHERE c1.descendant = :parentId";
@@ -312,29 +315,4 @@ class Closure implements Strategy
             }
         }
     }
-
-    /**
-     * Extracts identifiers from object or proxy
-     *
-     * @param EntityManager $em
-     * @param object $entity
-     * @param bool $single
-     * @return mixed - array or single identifier
-     */
-    private function extractIdentifier(EntityManager $em, $entity, $single = true)
-    {
-        if ($entity instanceof Proxy) {
-            $id = $em->getUnitOfWork()->getEntityIdentifier($entity);
-        } else {
-            $meta = $em->getClassMetadata(get_class($entity));
-            $id = array();
-            foreach ($meta->identifier as $name) {
-                $id[$name] = $meta->getReflectionProperty($name)->getValue($entity);
-            }
-        }
-        if ($single) {
-            $id = current($id);
-        }
-        return $id;
-    }
 }