/** * Handles the response * * @param string $soapMessage The response * * @throws Exception * * @return \SimpleXMLElement The response XML <Body> tag */ private function handleResponse($soapMessage) { // No message is returned, something went wrong, throw a Soap exception which // means there was an error communicating with the soap webservice` if (!$soapMessage) { throw new SoapException($this->getCurlClient()->getError(), $this->getCurlClient()->getErrorNr()); } // Construct a SimpleXMLElement from the message $xml = new \SimpleXMLElement($soapMessage); if (self::$debug === true) { echo "<h2>RESPONSE</h2></hr />"; echo '<pre>', htmlentities(self::formatXml($xml->asXml())), '</pre>'; } // If the response is a Fault throw a webservice exception $fault = $xml->children('soap', true)->Body->Fault; if ($fault) { throw self::getExceptionForFault($fault->Detail->children()->Error->Code->__toString()); } // Return the body element from the XML return $xml->children('soap', true)->Body; }
/** * @param $rawData * @return array * @throws \Thelia\Core\FileFormat\Formatting\Exception\BadFormattedStringException */ public function rawDecode($rawData) { try { $xml = new SimpleXMLElement($rawData); } catch (\Exception $e) { $errorMessage = $this->translator->trans("You tried to load a bad formatted XML"); $this->logger->error($errorMessage . ": " . $e->getMessage()); throw new BadFormattedStringException($errorMessage); } $array = []; foreach ($xml->children() as $child) { $this->recursiveRawDecode($array, $child); } return $array; }
/** * Parse one customergroupacl * * @param SimpleXMLElement $customerGroupAcl A customergroupacl * @param CustomerGroup $customerGroupModel CustomerGroup propel object for who the access have to be created * * @throws \Exception When an error is detected on xml file (customer group or acl don't exist) */ protected function parseCustomerGroupAcl(SimpleXMLElement $customerGroupAcl, CustomerGroup $customerGroupModel) { $acl = AclQuery::create()->findOneByCode($customerGroupAcl->getAttributeAsPhp('aclcode')); if (null === $customerGroupModel) { throw new \Exception($this->translator->trans("Error in %a file the customer group '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupModel->getCode()], CustomerGroupAcl::DOMAIN_MESSAGE)); } if (null === $acl) { throw new \Exception($this->translator->trans("Error in %a file the acl '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupAcl->getAttributeAsPhp('aclcode')], CustomerGroupAcl::DOMAIN_MESSAGE)); } $this->parseAccesses($customerGroupAcl->children(), $acl, $customerGroupModel); }