Ejemplo n.º 1
0
 public function testAddArray()
 {
     $books = ['book' => [['title' => 'Book 01', 'public' => 1999, 'publisher' => 'Publisher 01', 'author' => [['name' => 'Author 01'], ['name' => 'Author 02']]], ['title' => 'Book 02', 'public' => 1999, 'publisher' => 'Publisher 02', 'author' => ['name' => 'Author 04']], ['title' => 'Book 03', 'public' => 1999, 'publisher' => 'Publisher 03', 'author' => [['name' => 'Author 01'], ['name' => 'Author 03']]]]];
     $xml = new SimpleXML('<books />');
     $xml->addArray($books);
     $this->assertXmlStringEqualsXmlString($this->_xmlString, $xml->asXml());
 }
Ejemplo n.º 2
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.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * Method returning the xml representation of this class
  *
  * @return SimpleXML
  */
 public function toXml()
 {
     $soapNamespace = $this->_version === self::SOAP_1_2 ? self::NS_SOAP_1_2 : self::NS_SOAP_1_1;
     $nsString = 'xmlns:env="' . $soapNamespace . '"';
     foreach ($this->_namespaces as $key => $ns) {
         if ($key > 0) {
             $nsString .= sprintf(' xmlns:urn%d="%s"', $key, $ns);
         } else {
             $nsString .= sprintf(' xmlns:urn="%s"', $ns);
         }
     }
     $message = sprintf('<env:Envelope %s></env:Envelope>', $nsString);
     $xml = new SimpleXML($message);
     if (count($this->_headers)) {
         $header = $xml->addChild('Header')->addChild('context', null, 'urn:zimbra');
         foreach ($this->_headers as $name => $value) {
             $header->addChild($name, $value);
         }
     }
     $body = $xml->addChild('Body');
     $body->append($this->_body, $this->_request->getXmlNamespace());
     return $xml;
 }
Ejemplo n.º 5
0
 /**
  * Method returning the xml representation of this class
  *
  * @param  string $name
  * @return SimpleXML
  */
 public function toXml($name = null)
 {
     $this->emit('before', [$this]);
     $name = !empty($name) ? $name : $this->className();
     if (null !== $this->_value) {
         $xml = new SimpleXML('<' . $name . '>' . $this->_value . '</' . $name . '>');
     } else {
         $xml = new SimpleXML('<' . $name . ' />');
     }
     foreach ($this->_properties as $key => $value) {
         if ($value instanceof \Zimbra\Enum\Base) {
             $xml->addAttribute($key, $value->value());
         } elseif (is_bool($value)) {
             $xml->addAttribute($key, Text::boolToString($value));
         } else {
             $xml->addAttribute($key, $value);
         }
     }
     if (count($this->_children)) {
         foreach ($this->_children as $key => $value) {
             if ($value instanceof \Zimbra\Struct\Base) {
                 $xml->append($value->toXml($key), $value->GetXmlNamespace());
             } elseif ($value instanceof \Zimbra\Enum\Base) {
                 $xml->addChild($key, $value->value());
             } elseif (is_bool($value)) {
                 $xml->addChild($key, Text::boolToString($value));
             } elseif (is_array($value)) {
                 foreach ($value as $child) {
                     if ($child instanceof \Zimbra\Struct\Base) {
                         $xml->append($child->toXml($key), $child->GetXmlNamespace());
                     } elseif ($child instanceof \Zimbra\Enum\Base) {
                         $xml->addChild($key, $child->value());
                     } elseif (is_bool($child)) {
                         $xml->addChild($key, Text::boolToString($child));
                     } else {
                         $xml->addChild($key, $child);
                     }
                 }
             } else {
                 $xml->addChild($key, $value);
             }
         }
     }
     $this->emit('after.xml', [$xml]);
     return $xml;
 }
Ejemplo n.º 6
0
 /**
  * Method returning the xml representation of this class
  *
  * @param  string $name
  * @return SimpleXML
  */
 public function toXml($name = null)
 {
     $name = empty($name) ? $this->requestName() : $name;
     $xml = new SimpleXML('<' . $name . ' />');
     foreach ($this->_requests as $key => $request) {
         $requestXml = $request->toXml();
         $requestXml->addAttribute('requestId', $key);
         $xml->append($requestXml, $request->getXmlNamespace());
     }
     return $xml;
 }