示例#1
0
 /**
  * @param \SimpleXMLElement $xml
  *
  * @return Response
  */
 public function fromXml(\SimpleXMLElement $xml)
 {
     $response = new Response($this->getAddress());
     foreach ($xml->AddressValidationResult as $rating) {
         $address = new Address();
         $address->setIsResponse();
         $address->setCity((string) $rating->Address->City)->setStateProvinceCode((string) $rating->Address->StateProvinceCode);
         $regionSuggestion = new RegionSuggestion();
         $regionSuggestion->setRank((int) $rating->Rank);
         $regionSuggestion->setQuality((double) $rating->Quality);
         $regionSuggestion->setAddress($address);
         $regionSuggestion->setPostalCodeLowEnd((string) $rating->PostalCodeLowEnd);
         $regionSuggestion->setPostalCodeHighEnd((string) $rating->PostalCodeHighEnd);
         $response->addSuggestedRegion($regionSuggestion);
     }
     return $response;
 }
示例#2
0
 /**
  * Create an address from XML.  SimpleXMLElement passed must have immediate children like AddressLine1, City, etc.
  * @internal
  *
  * @param \SimpleXMLElement $xml
  *
  * @return \SimpleUPS\Address
  */
 public static function fromXml(\SimpleXMLElement $xml)
 {
     $address = new Address();
     $address->setIsResponse();
     //@todo Consider alternatives for what to do with Consignee
     if (isset($xml->AddressLine1)) {
         $street = $xml->AddressLine1;
         if (isset($xml->AddressLine2)) {
             $street .= ' ' . $xml->AddressLine2;
         }
         if (isset($xml->AddressLine3)) {
             $street .= ' ' . $xml->AddressLine3;
         }
         $address->setStreet(trim((string) $street));
     }
     if (isset($xml->City)) {
         $address->setCity($xml->City);
     }
     if (isset($xml->StateProvinceCode)) {
         $address->setStateProvinceCode((string) $xml->StateProvinceCode);
     }
     if (isset($xml->PostalCode)) {
         $address->setPostalCode((string) $xml->PostalCode);
     }
     if (isset($xml->CountryCode)) {
         $address->setCountryCode((string) $xml->CountryCode);
     }
     return $address;
 }
示例#3
0
 /**
  * @return array
  */
 public function jsonSerialize()
 {
     return array_merge(parent::jsonSerialize(), array('classification' => $this->getClassification(), 'isResidential' => $this->isResidential()));
 }
示例#4
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;
 }
示例#5
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;
 }