/** * @param \SimpleXMLElement $xml * * @return Box * @throws BpostInvalidValueException * @throws BpostNotImplementedException */ public static function createFromXML(\SimpleXMLElement $xml) { $box = new Box(); if (isset($xml->sender)) { $box->setSender(Sender::createFromXML($xml->sender->children('http://schema.post.be/shm/deepintegration/v3/common'))); } if (isset($xml->nationalBox)) { /** @var \SimpleXMLElement $nationalBoxData */ $nationalBoxData = $xml->nationalBox->children('http://schema.post.be/shm/deepintegration/v3/national'); // build classname based on the tag name $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($nationalBoxData->getName()); if ($nationalBoxData->getName() == 'at24-7') { $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\At247'; } if (!method_exists($className, 'createFromXML')) { throw new BpostNotImplementedException(); } $nationalBox = call_user_func(array($className, 'createFromXML'), $nationalBoxData); $box->setNationalBox($nationalBox); } if (isset($xml->internationalBox)) { /** @var \SimpleXMLElement $internationalBoxData */ $internationalBoxData = $xml->internationalBox->children('http://schema.post.be/shm/deepintegration/v3/international'); // build classname based on the tag name $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($internationalBoxData->getName()); if (!method_exists($className, 'createFromXML')) { var_dump($className); throw new BpostNotImplementedException(); } $internationalBox = call_user_func(array($className, 'createFromXML'), $internationalBoxData); $box->setInternationalBox($internationalBox); } if (isset($xml->remark) && $xml->remark != '') { $box->setRemark((string) $xml->remark); } if (isset($xml->additionalCustomerReference) && $xml->additionalCustomerReference != '') { $box->setAdditionalCustomerReference((string) $xml->additionalCustomerReference); } if (!empty($xml->barcode)) { $box->setBarcode((string) $xml->barcode); } if (isset($xml->status) && $xml->status != '') { $box->setStatus((string) $xml->status); } return $box; }