You are here

function nusoap_base::serializeEnvelope in Salesforce Suite 5

Same name in this branch
  1. 5 includes/nusoap.php \nusoap_base::serializeEnvelope()
  2. 5 includes/nusoap.orig.php \nusoap_base::serializeEnvelope()
Same name and namespace in other branches
  1. 5.2 includes/nusoap.php \nusoap_base::serializeEnvelope()
  2. 5.2 includes/nusoap.orig.php \nusoap_base::serializeEnvelope()

serializes a message

@access public

Parameters

string $body the XML of the SOAP body:

mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers:

array $namespaces optional the namespaces used in generating the body and headers:

string $style optional (rpc|document):

string $use optional (encoded|literal):

string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded):

Return value

string the message

File

includes/nusoap.php, line 614

Class

nusoap_base
nusoap_base

Code

function serializeEnvelope($body, $headers = false, $namespaces = [], $style = 'rpc', $use = 'encoded', $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/') {

  // TODO: add an option to automatically run utf8_encode on $body and $headers
  // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
  // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
  $this
    ->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style={$style} use={$use} encodingStyle={$encodingStyle}");
  $this
    ->debug("headers:");
  $this
    ->appendDebug($this
    ->varDump($headers));
  $this
    ->debug("namespaces:");
  $this
    ->appendDebug($this
    ->varDump($namespaces));

  // serialize namespaces
  $ns_string = '';
  foreach (array_merge($this->namespaces, $namespaces) as $k => $v) {
    $ns_string .= " xmlns:{$k}=\"{$v}\"";
  }
  if ($encodingStyle) {
    $ns_string = " SOAP-ENV:encodingStyle=\"{$encodingStyle}\"{$ns_string}";
  }

  // serialize headers
  if ($headers) {
    if (is_array($headers)) {
      $xml = '';
      foreach ($headers as $header) {
        $xml .= $this
          ->serialize_val($header, false, false, false, false, false, $use);
      }
      $headers = $xml;
      $this
        ->debug("In serializeEnvelope, serialzied array of headers to {$headers}");
    }
    $headers = "<SOAP-ENV:Header>" . $headers . "</SOAP-ENV:Header>";
  }

  // serialize envelope
  return '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?' . ">" . '<SOAP-ENV:Envelope' . $ns_string . ">" . $headers . "<SOAP-ENV:Body>" . $body . "</SOAP-ENV:Body>" . "</SOAP-ENV:Envelope>";
}