public function testAdDateConversion()
 {
     $adTimestamp = '130898490540000000.0Z';
     $decorator = Converter::fromAdDateTime($adTimestamp);
     $convertedAdTimestamp = Converter::toAdDateTime($decorator);
     $this->assertEquals($adTimestamp, $convertedAdTimestamp);
 }
 public function entryToEntity($entityName, $entryData)
 {
     $instanceMetadataCollection = $this->getClassMetadata($entityName);
     $entryData = $this->cleanArray($entryData);
     $dn = $entryData['dn'];
     $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 this this gets applied from the entry to the entity first.
     if (!empty($entryData['cn'][0])) {
         $entity->setCn($entryData['cn'][0]);
     }
     foreach ($metaDatas as $attrName => $attrValue) {
         $attrValue = strtolower($attrValue);
         if ($instanceMetadataCollection->isArrayOfLink($attrName)) {
             $entityArray = array();
             if (!isset($entryData[$attrValue])) {
                 $entryData[$attrValue] = array('count' => 0);
             }
             $linkArray = $entryData[$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($entryData[$attrValue])) {
                 continue;
                 // Don't set the atribute if not exit
             }
             try {
                 if (preg_match('/^\\d{14}/', $entryData[$attrValue][0])) {
                     if ($this->isActiveDirectory) {
                         $datetime = Converter::fromAdDateTime($entryData[$attrValue][0], false);
                     } else {
                         $datetime = Converter::fromLdapDateTime($entryData[$attrValue][0], false);
                     }
                     $entity->{$setter}($datetime);
                 } elseif ($instanceMetadataCollection->isArrayField($attrName)) {
                     unset($entryData[$attrValue]["count"]);
                     $entity->{$setter}($entryData[$attrValue]);
                 } else {
                     $entity->{$setter}($entryData[$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, $entryData['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;
 }