You are here

function wsdl::parseWSDL in Salesforce Suite 5

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

parses the wsdl document

@access private

Parameters

string $wsdl path or URL:

2 calls to wsdl::parseWSDL()
wsdl::wsdl in includes/nusoap.php
constructor
wsdl::wsdl in includes/nusoap.orig.php
constructor

File

includes/nusoap.orig.php, line 4225

Class

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

Code

function parseWSDL($wsdl = '') {
  if ($wsdl == '') {
    $this
      ->debug('no wsdl passed to parseWSDL()!!');
    $this
      ->setError('no wsdl passed to parseWSDL()!!');
    return false;
  }

  // parse $wsdl for url format
  $wsdl_props = parse_url($wsdl);
  if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
    $this
      ->debug('getting WSDL http(s) URL ' . $wsdl);

    // get wsdl
    $tr = new soap_transport_http($wsdl);
    $tr->request_method = 'GET';
    $tr->useSOAPAction = false;
    if ($this->proxyhost && $this->proxyport) {
      $tr
        ->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
    }
    $tr
      ->setEncoding('gzip, deflate');
    $wsdl_string = $tr
      ->send('', $this->timeout, $this->response_timeout);

    //$this->debug("WSDL request\n" . $tr->outgoing_payload);

    //$this->debug("WSDL response\n" . $tr->incoming_payload);
    $this
      ->appendDebug($tr
      ->getDebug());

    // catch errors
    if ($err = $tr
      ->getError()) {
      $errstr = 'HTTP ERROR: ' . $err;
      $this
        ->debug($errstr);
      $this
        ->setError($errstr);
      unset($tr);
      return false;
    }
    unset($tr);
    $this
      ->debug("got WSDL URL");
  }
  else {

    // $wsdl is not http(s), so treat it as a file URL or plain file path
    if (isset($wsdl_props['scheme']) && $wsdl_props['scheme'] == 'file' && isset($wsdl_props['path'])) {
      $path = isset($wsdl_props['host']) ? $wsdl_props['host'] . ':' . $wsdl_props['path'] : $wsdl_props['path'];
    }
    else {
      $path = $wsdl;
    }
    $this
      ->debug('getting WSDL file ' . $path);
    if ($fp = @fopen($path, 'r')) {
      $wsdl_string = '';
      while ($data = fread($fp, 32768)) {
        $wsdl_string .= $data;
      }
      fclose($fp);
    }
    else {
      $errstr = "Bad path to WSDL file {$path}";
      $this
        ->debug($errstr);
      $this
        ->setError($errstr);
      return false;
    }
  }
  $this
    ->debug('Parse WSDL');

  // end new code added
  // Create an XML parser.
  $this->parser = xml_parser_create();

  // Set the options for parsing the XML data.
  // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);

  // Set the object for the parser.
  xml_set_object($this->parser, $this);

  // Set the element handlers for the parser.
  xml_set_element_handler($this->parser, 'start_element', 'end_element');
  xml_set_character_data_handler($this->parser, 'character_data');

  // Parse the XML file.
  if (!xml_parse($this->parser, $wsdl_string, true)) {

    // Display an error message.
    $errstr = sprintf('XML error parsing WSDL from %s on line %d: %s', $wsdl, xml_get_current_line_number($this->parser), xml_error_string(xml_get_error_code($this->parser)));
    $this
      ->debug($errstr);
    $this
      ->debug("XML payload:\n" . $wsdl_string);
    $this
      ->setError($errstr);
    return false;
  }

  // free the parser
  xml_parser_free($this->parser);
  $this
    ->debug('Parsing WSDL done');

  // catch wsdl parse errors
  if ($this
    ->getError()) {
    return false;
  }
  return true;
}