コード例 #1
0
 /**
  * @param string $product Possible values are: bpack@bpost
  * @throws BpostInvalidValueException
  */
 public function setProduct($product)
 {
     if (!in_array($product, self::getPossibleProductValues())) {
         throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues());
     }
     parent::setProduct($product);
 }
コード例 #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;
 }