Example #1
0
 /**
  * @internal
  *
  * @param \SimpleXMLElement $xml
  *
  * @return Activity
  */
 public static function fromXml(\SimpleXMLElement $xml)
 {
     $activity = new Activity();
     $activity->setIsResponse();
     if (isset($xml->ActivityLocation->Code)) {
         $activity->setLocationCode($xml->ActivityLocation->Code);
     }
     if (isset($xml->ActivityLocation->Description)) {
         $activity->setLocationDescription($xml->ActivityLocation->Description);
     }
     if (isset($xml->ActivityLocation->SignedForByName)) {
         $activity->setSignedForBy($xml->ActivityLocation->SignedForByName);
     }
     if (isset($xml->Date) && isset($xml->Time)) {
         $activity->setTimestamp(new \DateTime($xml->Date . ' ' . $xml->Time));
     }
     if (isset($xml->Status->StatusType)) {
         $activity->setStatusType(StatusType::fromXml($xml->Status->StatusType));
     }
     if (isset($xml->Status->StatusCode)) {
         $activity->setStatusCode($xml->Status->StatusCode->Code);
     }
     if (isset($xml->ActivityLocation->Address)) {
         $activity->setAddress(Address::fromXml($xml->ActivityLocation->Address));
     }
     return $activity;
 }
Example #2
0
 /**
  * Create an address from XML.  SimpleXMLElement passed must have immediate children like AddressLine1, City, etc.
  * @internal
  *
  * @param \SimpleXMLElement $xml
  *
  * @return Package
  */
 public static function fromXml(\SimpleXMLElement $xml)
 {
     $package = new Package();
     $package->setIsResponse();
     if (isset($xml->TrackingNumber)) {
         $package->setTrackingNumber($xml->TrackingNumber);
     }
     if (isset($xml->RescheduledDeliveryDate) && isset($xml->RescheduledDeliveryTime)) {
         $package->setRescheduledDeliveryTime(new \DateTime(trim($xml->RescheduledDeliveryDate . ' ' . $xml->RescheduledDeliveryTime)));
     }
     if (isset($xml->ScheduledDeliveryDate) && isset($xml->ScheduledDeliveryTime)) {
         $package->setScheduledDeliveryTime(new \DateTime(trim($xml->ScheduledDeliveryDate . ' ' . $xml->ScheduledDeliveryTime)));
     }
     if (isset($xml->Reroute->Address)) {
         $package->setRerouteAddress(Address::fromXml($xml->Reroute->Address));
     }
     if (isset($xml->ReturnTo->Address)) {
         $package->setReturnToAddress(Address::fromXml($xml->ReturnTo->Address));
     }
     if (isset($xml->PackageServiceOptions->SignatureRequired->Code)) {
         $package->setSignatureType($xml->PackageServiceOptions->SignatureRequired->Code);
     }
     if (isset($xml->PackageWeight)) {
         $package->setWeight(Weight::fromXml($xml->PackageWeight));
     }
     if (isset($xml->ReferenceNumber)) {
         foreach ($xml->ReferenceNumber as $referenceNumber) {
             $package->addReferenceNumber(ReferenceNumber::fromXml($referenceNumber));
         }
     }
     if (isset($xml->Activity)) {
         foreach ($xml->Activity as $activity) {
             $package->addActivity(Activity::fromXml($activity));
         }
     }
     if (isset($xml->ShipmentWeight)) {
         $package->setWeight(Weight::fromXml($xml->ShipmentWeight));
     }
     if (isset($xml->LocationAssured)) {
         $package->setLocationAssured($xml->LocationAssured);
     }
     if (isset($xml->Accessorial)) {
         foreach ($xml->Accessorial as $accessorial) {
             $package->addAccessorial(Accessorial::fromXml($accessorial));
         }
     }
     return $package;
 }