Ejemplo n.º 1
0
 /**
  * Process soap response xml.
  *
  * @param  string $xml Soap response message in xml format.
  * @throws RuntimeException
  * @return mix
  */
 protected function processXml($xml)
 {
     if (empty($xml)) {
         throw new \UnexpectedValueException('Response string is empty.');
     }
     $xml = new SimpleXML($xml);
     $fault = $xml->children('soap', true)->Body->Fault;
     if ($fault) {
         throw new \RuntimeException($fault->children('soap', true)->Reason->Text);
     }
     return $xml->children('soap', true)->Body->children()->toObject();
 }
Ejemplo n.º 2
0
 /**
  * Append xml.
  *
  * @param  SimpleXML $xml.
  * @return self
  */
 public function append(SimpleXML $xml, $namespace = null)
 {
     $value = trim((string) $xml);
     $namespaces = array_values($xml->getNamespaces());
     if (isset($namespaces[0])) {
         $namespace = $namespaces[0];
     }
     $newChild = $this->addChild($xml->getName(), !empty($value) ? $value : null, $namespace);
     foreach ($xml->attributes() as $name => $value) {
         $newChild->addAttribute($name, $value);
     }
     foreach ($xml->children() as $child) {
         $newChild->append($child, $namespace);
     }
     return $this;
 }