Esempio n. 1
0
 /**
  * Sends a soap message and returns the response object.
  * NB: we define extra headers here and not in request obj because here we
  *     switch between soap 1.1 and 1.2 protocols in the client - but we need
  *     the request's name+ns for creating the soap 1.1 header...
  *     This could be probably be pushed down unto the request anyway
  * @param ggSOAPRequest $request
  * @return ggSOAPResponse
  * @todo raise an error if the request is not a soap one and has no ->ns() method
  */
 function send($request)
 {
     if ($this->SoapVersion != 0) {
         $request->setSOAPVersion($this->SoapVersion);
     }
     return parent::send($request);
 }
Esempio n. 2
0
 /**
   Returns the payload for the response.
 */
 function payload()
 {
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->name = "eZSOAP message";
     $root = $doc->createElementNS(ggSOAPRequest::ENV, ggSOAPRequest::ENV_PREFIX . ':Envelope');
     $root->setAttribute('xmlns:' . ggSOAPRequest::XSI_PREFIX, ggSOAPRequest::SCHEMA_INSTANCE);
     $root->setAttribute('xmlns:' . ggSOAPRequest::XSD_PREFIX, ggSOAPRequest::SCHEMA_DATA);
     $root->setAttribute('xmlns:' . ggSOAPRequest::ENC_PREFIX, ggSOAPRequest::ENC);
     // add the body
     $body = $doc->createElement(ggSOAPRequest::ENV_PREFIX . ':Body');
     $root->appendChild($body);
     // Check if it's a fault
     if ($this->Value instanceof ggWebservicesFault || $this->Value instanceof eZSOAPFault) {
         $fault = $doc->createElement(ggSOAPRequest::ENV_PREFIX . ':Fault');
         $faultCodeNode = $doc->createElement("faultcode", $this->Value->faultCode());
         $fault->appendChild($faultCodeNode);
         $faultStringNode = $doc->createElement("faultstring", $this->Value->faultString());
         $fault->appendChild($faultStringNode);
         $body->appendChild($fault);
     } else {
         // add the response
         $responseName = $this->Name . "Response";
         $response = $doc->createElement($responseName);
         $response->prefix = "resp";
         $response->setAttribute('xmlns:' . "resp", $this->ns);
         $return = $doc->createElement("return");
         $return->prefix = "resp";
         $value = ggSOAPRequest::encodeValue($doc, "return", $this->Value);
         $response->appendChild($value);
         $body->appendChild($response);
     }
     $doc->appendChild($root);
     return $doc->saveXML();
 }
Esempio n. 3
0
 /**
  * Encodes a PHP variable into a SOAP datatype.
  * @todo move this logic into ggWSDLParser class
  * @param DOMDocument $doc
  * @param string $name
  * @param mixed $value
  * @return DOMElement|false
  */
 static function encodeValue($doc, $name, $value)
 {
     switch (gettype($value)) {
         case "string":
             $node = $doc->createElement($name, $value);
             $node->setAttribute(ggSOAPRequest::XSI_PREFIX . ':type', ggSOAPRequest::XSD_PREFIX . ':string');
             return $node;
             break;
         case "boolean":
             $node = $doc->createElement($name, $value ? 'true' : 'false');
             $node->setAttribute(ggSOAPRequest::XSI_PREFIX . ':type', ggSOAPRequest::XSD_PREFIX . ':boolean');
             return $node;
             break;
         case "integer":
             $node = $doc->createElement($name, $value);
             $node->setAttribute(ggSOAPRequest::XSI_PREFIX . ':type', ggSOAPRequest::XSD_PREFIX . ':int');
             return $node;
             break;
         case "double":
             $node = $doc->createElement($name, $value);
             $node->setAttribute(ggSOAPRequest::XSI_PREFIX . ':type', ggSOAPRequest::XSD_PREFIX . ':float');
             return $node;
             break;
         case "array":
             $arrayCount = count($value);
             $isStruct = false;
             // Check for struct
             $i = 0;
             foreach ($value as $key => $val) {
                 if ($i !== $key) {
                     $isStruct = true;
                     break;
                 }
                 $i++;
             }
             if ($isStruct == true) {
                 $node = $doc->createElement($name);
                 $node->setAttribute(ggSOAPRequest::XSI_PREFIX . ':type', ggSOAPRequest::ENC_PREFIX . ':SOAPStruct');
                 foreach ($value as $key => $val) {
                     $subNode = ggSOAPRequest::encodeValue($doc, (string) $key, $val);
                     $node->appendChild($subNode);
                 }
                 return $node;
             } else {
                 $node = $doc->createElement($name);
                 $node->setAttribute(ggSOAPRequest::XSI_PREFIX . ':type', ggSOAPRequest::ENC_PREFIX . ':Array');
                 $node->setAttribute(ggSOAPRequest::ENC_PREFIX . ':arrayType', ggSOAPRequest::XSD_PREFIX . ":string[{$arrayCount}]");
                 foreach ($value as $arrayItem) {
                     $subNode = ggSOAPRequest::encodeValue($doc, "item", $arrayItem);
                     $node->appendChild($subNode);
                 }
                 return $node;
             }
             break;
     }
     return false;
 }