public function entryToEntity($entityName, $entryData)
 {
     $instanceMetadataCollection = $this->getClassMetadata($entityName);
     $cleanData = [];
     foreach (array_keys($entryData) as $key) {
         $cleanData[strtolower($key)] = $entryData[$key];
     }
     $dn = $cleanData['dn'];
     /**
      * @var LdapEntity $entity
      */
     $entity = new $entityName();
     $metaDatas = $instanceMetadataCollection->getMetadatas();
     // The 'cn' attribite is at the heart of LDAP entries and entities and is often required for
     // many other processes. Make sure this gets applied from the entry to the entity first.
     if (!empty($cleanData['cn'][0])) {
         $entity->setCn($cleanData['cn'][0]);
     }
     foreach ($metaDatas as $attrName => $attrValue) {
         $attrValue = strtolower($attrValue);
         if ($instanceMetadataCollection->isArrayOfLink($attrName)) {
             $entityArray = array();
             if (!isset($cleanData[$attrValue])) {
                 $cleanData[$attrValue] = array('count' => 0);
             }
             $linkArray = $cleanData[$attrValue];
             $count = $linkArray['count'];
             for ($i = 0; $i < $count; $i++) {
                 if ($linkArray[$i] != null) {
                     $targetArray = $this->retrieveByDn($linkArray[$i], $instanceMetadataCollection->getArrayOfLinkClass($attrName), 1);
                     $entityArray[] = $targetArray[0];
                 }
             }
             $setter = 'set' . ucfirst($attrName);
             $entity->{$setter}($entityArray);
         } else {
             $setter = 'set' . ucfirst($attrName);
             if (!isset($cleanData[$attrValue])) {
                 continue;
                 // Don't set the atribute if not exit
             }
             try {
                 if (preg_match('/^\\d{14}/', $cleanData[$attrValue][0])) {
                     if ($this->client->getIsActiveDirectory()) {
                         $datetime = Converter::fromAdDateTime($cleanData[$attrValue][0], false);
                     } else {
                         $datetime = Converter::fromLdapDateTime($cleanData[$attrValue][0], false);
                     }
                     $entity->{$setter}($datetime);
                 } elseif ($instanceMetadataCollection->isArrayField($attrName)) {
                     unset($cleanData[$attrValue]["count"]);
                     $entity->{$setter}($cleanData[$attrValue]);
                 } else {
                     $entity->{$setter}($cleanData[$attrValue][0]);
                 }
             } catch (Exception $e) {
                 $this->logger->err(sprintf("Exception in ldap to entity mapping : %s", $e->getMessage()));
             }
         }
     }
     foreach ($instanceMetadataCollection->getDnRegex() as $attrName => $regex) {
         preg_match_all($regex, $cleanData['dn'], $matches);
         $setter = 'set' . ucfirst($attrName);
         $entity->{$setter}($matches[1]);
     }
     if ($dn != '') {
         $entity->setDn($dn);
         foreach ($instanceMetadataCollection->getParentLink() as $attrName => $parentClass) {
             $setter = 'set' . ucfirst($attrName);
             $parentDn = preg_replace('/^[a-zA-Z0-9]*=[a-zA-Z0-9]*,/', '', $dn);
             $link = $this->retrieveByDn($parentDn, $parentClass);
             if (count($link) > 0) {
                 $entity->{$setter}($link[0]);
             }
         }
     }
     return $entity;
 }