You are here

function wsdl::serialize in Salesforce Suite 5

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

* serialize the parsed wsdl * *

Parameters

mixed $debug whether to put debug=1 in endpoint URL: * @return string serialization of WSDL * @access public

File

includes/nusoap.php, line 4874

Class

wsdl
parses a WSDL file, allows access to it's data, other utility methods

Code

function serialize($debug = 0) {
  $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  $xml .= "\n<definitions";
  foreach ($this->namespaces as $k => $v) {
    $xml .= " xmlns:{$k}=\"{$v}\"";
  }

  // 10.9.02 - add poulter fix for wsdl and tns declarations
  if (isset($this->namespaces['wsdl'])) {
    $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
  }
  if (isset($this->namespaces['tns'])) {
    $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
  }
  $xml .= '>';

  // imports
  if (sizeof($this->import) > 0) {
    foreach ($this->import as $ns => $list) {
      foreach ($list as $ii) {
        if ($ii['location'] != '') {
          $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
        }
        else {
          $xml .= '<import namespace="' . $ns . '" />';
        }
      }
    }
  }

  // types
  if (count($this->schemas) >= 1) {
    $xml .= "\n<types>";
    foreach ($this->schemas as $ns => $list) {
      foreach ($list as $xs) {
        $xml .= $xs
          ->serializeSchema();
      }
    }
    $xml .= '</types>';
  }

  // messages
  if (count($this->messages) >= 1) {
    foreach ($this->messages as $msgName => $msgParts) {
      $xml .= "\n<message name=\"" . $msgName . '">';
      if (is_array($msgParts)) {
        foreach ($msgParts as $partName => $partType) {

          // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
          if (strpos($partType, ':')) {
            $typePrefix = $this
              ->getPrefixFromNamespace($this
              ->getPrefix($partType));
          }
          elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {

            // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
            $typePrefix = 'xsd';
          }
          else {
            foreach ($this->typemap as $ns => $types) {
              if (isset($types[$partType])) {
                $typePrefix = $this
                  ->getPrefixFromNamespace($ns);
              }
            }
            if (!isset($typePrefix)) {
              die("{$partType} has no namespace!");
            }
          }
          $ns = $this
            ->getNamespaceFromPrefix($typePrefix);
          $typeDef = $this
            ->getTypeDef($this
            ->getLocalPart($partType), $ns);
          if ($typeDef['typeClass'] == 'element') {
            $elementortype = 'element';
          }
          else {
            $elementortype = 'type';
          }
          $xml .= '<part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $this
            ->getLocalPart($partType) . '" />';
        }
      }
      $xml .= '</message>';
    }
  }

  // bindings & porttypes
  if (count($this->bindings) >= 1) {
    $binding_xml = '';
    $portType_xml = '';
    foreach ($this->bindings as $bindingName => $attrs) {
      $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
      $binding_xml .= '<soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
      $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
      foreach ($attrs['operations'] as $opName => $opParts) {
        $binding_xml .= '<operation name="' . $opName . '">';
        $binding_xml .= '<soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>';
        if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
          $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
        }
        else {
          $enc_style = '';
        }
        $binding_xml .= '<input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
        if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
          $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
        }
        else {
          $enc_style = '';
        }
        $binding_xml .= '<output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
        $binding_xml .= '</operation>';
        $portType_xml .= '<operation name="' . $opParts['name'] . '"';
        if (isset($opParts['parameterOrder'])) {
          $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
        }
        $portType_xml .= '>';
        if (isset($opParts['documentation']) && $opParts['documentation'] != '') {
          $portType_xml .= '<documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
        }
        $portType_xml .= '<input message="tns:' . $opParts['input']['message'] . '"/>';
        $portType_xml .= '<output message="tns:' . $opParts['output']['message'] . '"/>';
        $portType_xml .= '</operation>';
      }
      $portType_xml .= '</portType>';
      $binding_xml .= '</binding>';
    }
    $xml .= $portType_xml . $binding_xml;
  }

  // services
  $xml .= "\n<service name=\"" . $this->serviceName . '">';
  if (count($this->ports) >= 1) {
    foreach ($this->ports as $pName => $attrs) {
      $xml .= '<port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
      $xml .= '<soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
      $xml .= '</port>';
    }
  }
  $xml .= '</service>';
  return $xml . "\n</definitions>";
}