/** * @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; }
/** * 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; }