/**
  * @param  \SimpleXMLElement $xml
  *
  * @return International
  * @throws BpostInvalidValueException
  * @throws BpostNotImplementedException
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $international = new International();
     if (isset($xml->international->product) && $xml->international->product != '') {
         $international->setProduct((string) $xml->international->product);
     }
     if (isset($xml->international->options)) {
         /** @var \SimpleXMLElement $optionData */
         foreach ($xml->international->options as $optionData) {
             $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
             if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED))) {
                 $option = Messaging::createFromXML($optionData);
             } else {
                 $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName());
                 if (!method_exists($className, 'createFromXML')) {
                     throw new BpostNotImplementedException();
                 }
                 $option = call_user_func(array($className, 'createFromXML'), $optionData);
             }
             $international->addOption($option);
         }
     }
     if (isset($xml->international->parcelWeight) && $xml->international->parcelWeight != '') {
         $international->setParcelWeight((int) $xml->international->parcelWeight);
     }
     if (isset($xml->international->receiver)) {
         $receiverData = $xml->international->receiver->children('http://schema.post.be/shm/deepintegration/v3/common');
         $international->setReceiver(Receiver::createFromXML($receiverData));
     }
     if (isset($xml->international->customsInfo)) {
         $international->setCustomsInfo(CustomsInfo::createFromXML($xml->international->customsInfo));
     }
     return $international;
 }
Esempio n. 2
0
 /**
  * @param \SimpleXMLElement $nationalXml
  * @param National          $self
  * @return AtHome
  * @throws BpostException
  * @throws BpostXmlInvalidItemException
  */
 public static function createFromXML(\SimpleXMLElement $nationalXml, self $self = null)
 {
     if ($self === null) {
         throw new BpostException('Set an instance of National');
     }
     if (isset($nationalXml->product) && $nationalXml->product != '') {
         $self->setProduct((string) $nationalXml->product);
     }
     if (isset($nationalXml->options) && !empty($nationalXml->options)) {
         /** @var \SimpleXMLElement $optionData */
         foreach ($nationalXml->options as $optionData) {
             $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
             if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED, Messaging::MESSAGING_TYPE_INFO_NEXT_DAY, Messaging::MESSAGING_TYPE_INFO_REMINDER, Messaging::MESSAGING_TYPE_KEEP_ME_INFORMED))) {
                 $option = Messaging::createFromXML($optionData);
             } else {
                 switch ($optionData->getName()) {
                     case 'insured':
                         $class = 'Insurance';
                         break;
                     default:
                         $class = ucfirst($optionData->getName());
                 }
                 $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . $class;
                 if (!method_exists($className, 'createFromXML')) {
                     throw new BpostXmlInvalidItemException();
                 }
                 $option = call_user_func(array($className, 'createFromXML'), $optionData);
             }
             $self->addOption($option);
         }
     }
     if (isset($nationalXml->weight) && $nationalXml->weight != '') {
         $self->setWeight((int) $nationalXml->weight);
     }
     if (isset($nationalXml->openingHours) && $nationalXml->openingHours != '') {
         foreach ($nationalXml->openingHours->children() as $day => $value) {
             $self->addOpeningHour(new Day($day, (string) $value));
         }
     }
     if (isset($nationalXml->desiredDeliveryPlace) && $nationalXml->desiredDeliveryPlace != '') {
         $self->setDesiredDeliveryPlace((string) $nationalXml->desiredDeliveryPlace);
     }
     return $self;
 }
Esempio n. 3
0
 /**
  * @param  \SimpleXMLElement $xml
  *
  * @return AtBpost
  * @throws BpostInvalidValueException
  * @throws BpostNotImplementedException
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $atBpost = new AtBpost();
     if (isset($xml->atBpost->product) && $xml->atBpost->product != '') {
         $atBpost->setProduct((string) $xml->atBpost->product);
     }
     if (isset($xml->atBpost->options)) {
         /** @var \SimpleXMLElement $optionData */
         foreach ($xml->atBpost->options as $optionData) {
             $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
             if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED, Messaging::MESSAGING_TYPE_INFO_NEXT_DAY, Messaging::MESSAGING_TYPE_INFO_REMINDER, Messaging::MESSAGING_TYPE_KEEP_ME_INFORMED))) {
                 $option = Messaging::createFromXML($optionData);
             } else {
                 $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName());
                 if (!method_exists($className, 'createFromXML')) {
                     throw new BpostNotImplementedException();
                 }
                 $option = call_user_func(array($className, 'createFromXML'), $optionData);
             }
             $atBpost->addOption($option);
         }
     }
     if (isset($xml->atBpost->weight) && $xml->atBpost->weight != '') {
         $atBpost->setWeight((int) $xml->atBpost->weight);
     }
     if (isset($xml->atBpost->receiverName) && $xml->atBpost->receiverName != '') {
         $atBpost->setReceiverName((string) $xml->atBpost->receiverName);
     }
     if (isset($xml->atBpost->receiverCompany) && $xml->atBpost->receiverCompany != '') {
         $atBpost->setReceiverCompany((string) $xml->atBpost->receiverCompany);
     }
     if (isset($xml->atBpost->pugoId) && $xml->atBpost->pugoId != '') {
         $atBpost->setPugoId((string) $xml->atBpost->pugoId);
     }
     if (isset($xml->atBpost->pugoName) && $xml->atBpost->pugoName != '') {
         $atBpost->setPugoName((string) $xml->atBpost->pugoName);
     }
     if (isset($xml->atBpost->pugoAddress)) {
         /** @var \SimpleXMLElement $pugoAddressData */
         $pugoAddressData = $xml->atBpost->pugoAddress->children('http://schema.post.be/shm/deepintegration/v3/common');
         $atBpost->setPugoAddress(PugoAddress::createFromXML($pugoAddressData));
     }
     if (isset($xml->atBpost->requestedDeliveryDate) && $xml->atBpost->requestedDeliveryDate != '') {
         $atBpost->setRequestedDeliveryDate((string) $xml->atBpost->requestedDeliveryDate);
     }
     if (isset($xml->atBpost->shopHandlingInstruction) && $xml->atBpost->shopHandlingInstruction != '') {
         $atBpost->setShopHandlingInstruction((string) $xml->atBpost->shopHandlingInstruction);
     }
     return $atBpost;
 }
Esempio n. 4
0
 /**
  * @param  \SimpleXMLElement $xml
  *
  * @return Messaging
  * @throws BpostInvalidLengthException
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $messaging = new Messaging($xml->getName(), (string) $xml->attributes()->language);
     $data = $xml->{$xml->getName()};
     if (isset($data->emailAddress) && $data->emailAddress != '') {
         $messaging->setEmailAddress((string) $data->emailAddress);
     }
     if (isset($data->mobilePhone) && $data->mobilePhone != '') {
         $messaging->setMobilePhone((string) $data->mobilePhone);
     }
     return $messaging;
 }