You are here

function wsdl::start_element in Salesforce Suite 5

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

start-element handler

@access private

Parameters

string $parser XML parser object:

string $name element name:

string $attrs associative array of attributes:

File

includes/nusoap.orig.php, line 4325

Class

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

Code

function start_element($parser, $name, $attrs) {
  if ($this->status == 'schema') {
    $this->currentSchema
      ->schemaStartElement($parser, $name, $attrs);
    $this
      ->appendDebug($this->currentSchema
      ->getDebug());
    $this->currentSchema
      ->clearDebug();
  }
  elseif (ereg('schema$', $name)) {
    $this
      ->debug('Parsing WSDL schema');

    // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
    $this->status = 'schema';
    $this->currentSchema = new xmlschema('', '', $this->namespaces);
    $this->currentSchema
      ->schemaStartElement($parser, $name, $attrs);
    $this
      ->appendDebug($this->currentSchema
      ->getDebug());
    $this->currentSchema
      ->clearDebug();
  }
  else {

    // position in the total number of elements, starting from 0
    $pos = $this->position++;
    $depth = $this->depth++;

    // set self as current value for this depth
    $this->depth_array[$depth] = $pos;
    $this->message[$pos] = array(
      'cdata' => '',
    );

    // process attributes
    if (count($attrs) > 0) {

      // register namespace declarations
      foreach ($attrs as $k => $v) {
        if (ereg("^xmlns", $k)) {
          if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
            $this->namespaces[$ns_prefix] = $v;
          }
          else {
            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
          }
          if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
            $this->XMLSchemaVersion = $v;
            $this->namespaces['xsi'] = $v . '-instance';
          }
        }
      }

      // expand each attribute prefix to its namespace
      foreach ($attrs as $k => $v) {
        $k = strpos($k, ':') ? $this
          ->expandQname($k) : $k;
        if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
          $v = strpos($v, ':') ? $this
            ->expandQname($v) : $v;
        }
        $eAttrs[$k] = $v;
      }
      $attrs = $eAttrs;
    }
    else {
      $attrs = array();
    }

    // get element prefix, namespace and name
    if (ereg(':', $name)) {

      // get ns prefix
      $prefix = substr($name, 0, strpos($name, ':'));

      // get ns
      $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';

      // get unqualified name
      $name = substr(strstr($name, ':'), 1);
    }

    // process attributes, expanding any prefixes to namespaces
    // find status, register data
    switch ($this->status) {
      case 'message':
        if ($name == 'part') {
          if (isset($attrs['type'])) {
            $this
              ->debug("msg " . $this->currentMessage . ": found part {$attrs['name']}: " . implode(',', $attrs));
            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
          }
          if (isset($attrs['element'])) {
            $this
              ->debug("msg " . $this->currentMessage . ": found part {$attrs['name']}: " . implode(',', $attrs));
            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'];
          }
        }
        break;
      case 'portType':
        switch ($name) {
          case 'operation':
            $this->currentPortOperation = $attrs['name'];
            $this
              ->debug("portType {$this->currentPortType} operation: {$this->currentPortOperation}");
            if (isset($attrs['parameterOrder'])) {
              $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
            }
            break;
          case 'documentation':
            $this->documentation = true;
            break;

          // merge input/output data
          default:
            $m = isset($attrs['message']) ? $this
              ->getLocalPart($attrs['message']) : '';
            $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
            break;
        }
        break;
      case 'binding':
        switch ($name) {
          case 'binding':

            // get ns prefix
            if (isset($attrs['style'])) {
              $this->bindings[$this->currentBinding]['prefix'] = $prefix;
            }
            $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
            break;
          case 'header':
            $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
            break;
          case 'operation':
            if (isset($attrs['soapAction'])) {
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
            }
            if (isset($attrs['style'])) {
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
            }
            if (isset($attrs['name'])) {
              $this->currentOperation = $attrs['name'];
              $this
                ->debug("current binding operation: {$this->currentOperation}");
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
            }
            break;
          case 'input':
            $this->opStatus = 'input';
            break;
          case 'output':
            $this->opStatus = 'output';
            break;
          case 'body':
            if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
            }
            else {
              $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
            }
            break;
        }
        break;
      case 'service':
        switch ($name) {
          case 'port':
            $this->currentPort = $attrs['name'];
            $this
              ->debug('current port: ' . $this->currentPort);
            $this->ports[$this->currentPort]['binding'] = $this
              ->getLocalPart($attrs['binding']);
            break;
          case 'address':
            $this->ports[$this->currentPort]['location'] = $attrs['location'];
            $this->ports[$this->currentPort]['bindingType'] = $namespace;
            $this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
            $this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
            break;
        }
        break;
    }

    // set status
    switch ($name) {
      case 'import':
        if (isset($attrs['location'])) {
          $this->import[$attrs['namespace']][] = array(
            'location' => $attrs['location'],
            'loaded' => false,
          );
          $this
            ->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')');
        }
        else {
          $this->import[$attrs['namespace']][] = array(
            'location' => '',
            'loaded' => true,
          );
          if (!$this
            ->getPrefixFromNamespace($attrs['namespace'])) {
            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
          }
          $this
            ->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')');
        }
        break;

      //wait for schema

      //case 'types':

      //	$this->status = 'schema';
      //	break;
      case 'message':
        $this->status = 'message';
        $this->messages[$attrs['name']] = array();
        $this->currentMessage = $attrs['name'];
        break;
      case 'portType':
        $this->status = 'portType';
        $this->portTypes[$attrs['name']] = array();
        $this->currentPortType = $attrs['name'];
        break;
      case "binding":
        if (isset($attrs['name'])) {

          // get binding name
          if (strpos($attrs['name'], ':')) {
            $this->currentBinding = $this
              ->getLocalPart($attrs['name']);
          }
          else {
            $this->currentBinding = $attrs['name'];
          }
          $this->status = 'binding';
          $this->bindings[$this->currentBinding]['portType'] = $this
            ->getLocalPart($attrs['type']);
          $this
            ->debug("current binding: {$this->currentBinding} of portType: " . $attrs['type']);
        }
        break;
      case 'service':
        $this->serviceName = $attrs['name'];
        $this->status = 'service';
        $this
          ->debug('current service: ' . $this->serviceName);
        break;
      case 'definitions':
        foreach ($attrs as $name => $value) {
          $this->wsdl_info[$name] = $value;
        }
        break;
    }
  }
}