Example #1
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Customer
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     // @todo work with classmaps ...
     if (!isset($xml->UserID)) {
         throw new Exception('No UserId found.');
     }
     $customer = new Customer();
     if (isset($xml->UserID) && $xml->UserID != '') {
         $customer->setUserID((string) $xml->UserID);
     }
     if (isset($xml->FirstName) && $xml->FirstName != '') {
         $customer->setFirstName((string) $xml->FirstName);
     }
     if (isset($xml->LastName) && $xml->LastName != '') {
         $customer->setLastName((string) $xml->LastName);
     }
     if (isset($xml->Street) && $xml->Street != '') {
         $customer->setStreet((string) $xml->Street);
     }
     if (isset($xml->Number) && $xml->Number != '') {
         $customer->setNumber((string) $xml->Number);
     }
     if (isset($xml->CompanyName) && $xml->CompanyName != '') {
         $customer->setCompanyName((string) $xml->CompanyName);
     }
     if (isset($xml->DateOfBirth) && $xml->DateOfBirth != '') {
         $dateTime = new \DateTime((string) $xml->DateOfBirth);
         $customer->setDateOfBirth($dateTime);
     }
     if (isset($xml->DeliveryCode) && $xml->DeliveryCode != '') {
         $customer->setDeliveryCode((string) $xml->DeliveryCode);
     }
     if (isset($xml->Email) && $xml->Email != '') {
         $customer->setEmail((string) $xml->Email);
     }
     if (isset($xml->MobilePrefix) && $xml->MobilePrefix != '') {
         $customer->setMobilePrefix(trim((string) $xml->MobilePrefix));
     }
     if (isset($xml->MobileNumber) && $xml->MobileNumber != '') {
         $customer->setMobileNumber((string) $xml->MobileNumber);
     }
     if (isset($xml->Postalcode) && $xml->Postalcode != '') {
         $customer->setPostalCode((string) $xml->Postalcode);
     }
     if (isset($xml->PreferredLanguage) && $xml->PreferredLanguage != '') {
         $customer->setPreferredLanguage((string) $xml->PreferredLanguage);
     }
     if (isset($xml->ReceivePromotions) && $xml->ReceivePromotions != '') {
         $receivePromotions = in_array((string) $xml->ReceivePromotions, array('true', '1'));
         $customer->setReceivePromotions($receivePromotions);
     }
     if (isset($xml->actived) && $xml->actived != '') {
         $activated = in_array((string) $xml->actived, array('true', '1'));
         $customer->setActivated($activated);
     }
     if (isset($xml->Title) && $xml->Title != '') {
         $title = (string) $xml->Title;
         $title = ucfirst(strtolower($title));
         if (substr($title, -1) != '.') {
             $title .= '.';
         }
         $customer->setTitle($title);
     }
     if (isset($xml->Town) && $xml->Town != '') {
         $customer->setTown((string) $xml->Town);
     }
     if (isset($xml->PackStations->CustomerPackStation)) {
         foreach ($xml->PackStations->CustomerPackStation as $packStation) {
             $customer->addPackStation(CustomerPackStation::createFromXML($packStation));
         }
     }
     return $customer;
 }