xmlSecurity = $xmlSecurity; $this->errorProcessor = $errorProcessor; } /** * Validate DHL XML responses * * @param string $xmlResponse * @param bool $isShippingLabel * @return void * @throws DocumentValidationException */ public function validate($xmlResponse, $isShippingLabel = false) { if (strlen(trim($xmlResponse)) > 0 && strpos(trim($xmlResponse), 'xmlSecurity->scan($xmlResponse)) { throw new DocumentValidationException(__('The security validation of the XML document has failed.')); } $xml = simplexml_load_string($xmlResponse, \Magento\Shipping\Model\Simplexml\Element::class); if (in_array($xml->getName(), ['ErrorResponse', 'ShipmentValidateErrorResponse']) || isset($xml->GetQuoteResponse->Note->Condition) ) { /** @var \Magento\Framework\Phrase $exceptionPhrase */ $exceptionPhrase = $this->errorProcessor->process($xml, $isShippingLabel); throw new DocumentValidationException($exceptionPhrase, null, $exceptionPhrase->getArguments()[0]); } } else { throw new DocumentValidationException(__('The response is in the wrong format')); } } }