/** * @internal * * @param \SimpleXMLElement $xml * * @return Shipment */ public static function fromXml(\SimpleXMLElement $xml) { $shipment = new Shipment(); $shipment->setIsResponse(); if (isset($xml->PickupDate)) { $shipment->setPickupDate(new \DateTime((string) $xml->PickupDate)); } if (isset($xml->ScheduledDeliveryDate) && isset($xml->ScheduledDeliveryTime)) { $shipment->setDeliveryTime(new \DateTime((string) trim($xml->ScheduledDeliveryDate . ' ' . $xml->ScheduledDeliveryTime))); } if (isset($xml->ShipmentType)) { $shipment->setShipmentType(ShipmentType::fromXml($xml->ShipmentType)); } if (isset($xml->Shipper)) { $shipment->setShipper(Shipper::fromXml($xml->Shipper)); } if (isset($xml->ShipTo->Address)) { $shipment->setDestination(InstructionalAddress::fromXml($xml->ShipTo->Address)); } if (isset($xml->Package)) { foreach ($xml->Package as $package) { $shipment->addPackage(Package::fromXml($package)); } } if (isset($xml->Service)) { $shipment->setService(Service::fromXml($xml->Service)); } if (isset($xml->CurrentStatus)) { $shipment->setStatus(Status::fromXml($xml->CurrentStatus)); } if (isset($xml->ReferenceNumber)) { $shipment->setReferenceNumber(ReferenceNumber::fromXml($xml->ReferenceNumber)); } if (isset($xml->ShipmentWeight)) { $shipment->setWeight(\SimpleUPS\Weight::fromXml($xml->ShipmentWeight)); } if (isset($xml->ShipmentIdentificationNumber)) { $shipment->setShipmentIdentificationNumber($xml->ShipmentIdentificationNumber); } return $shipment; }
/** * 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; }