You are here

function wsdl::serializeParameters in Salesforce Suite 5

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

* serialize a PHP value according to a WSDL message definition * * TODO * - multi-ref serialization * - validate PHP values against type definitions, return errors if invalid * *

Parameters

string $ type name: * @param mixed $ param value * @return mixed new param or false if initial value didn't validate * @access public * @deprecated

File

includes/nusoap.php, line 5092

Class

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

Code

function serializeParameters($operation, $direction, $parameters) {
  $this
    ->debug("in serializeParameters: operation={$operation}, direction={$direction}, XMLSchemaVersion={$this->XMLSchemaVersion}");
  $this
    ->appendDebug('parameters=' . $this
    ->varDump($parameters));
  if ($direction != 'input' && $direction != 'output') {
    $this
      ->debug('The value of the \\$direction argument needs to be either "input" or "output"');
    $this
      ->setError('The value of the \\$direction argument needs to be either "input" or "output"');
    return false;
  }
  if (!($opData = $this
    ->getOperationData($operation))) {
    $this
      ->debug('Unable to retrieve WSDL data for operation: ' . $operation);
    $this
      ->setError('Unable to retrieve WSDL data for operation: ' . $operation);
    return false;
  }
  $this
    ->debug('opData:');
  $this
    ->appendDebug($this
    ->varDump($opData));

  // Get encoding style for output and set to current
  $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  if ($direction == 'input' && isset($opData['output']['encodingStyle']) && $opData['output']['encodingStyle'] != $encodingStyle) {
    $encodingStyle = $opData['output']['encodingStyle'];
    $enc_style = $encodingStyle;
  }

  // set input params
  $xml = '';
  if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
    $use = $opData[$direction]['use'];
    $this
      ->debug("use={$use}");
    $this
      ->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
    if (is_array($parameters)) {
      $parametersArrayType = $this
        ->isArraySimpleOrStruct($parameters);
      $this
        ->debug('have ' . $parametersArrayType . ' parameters');
      foreach ($opData[$direction]['parts'] as $name => $type) {
        $this
          ->debug('serializing part "' . $name . '" of type "' . $type . '"');

        // Track encoding style
        if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
          $encodingStyle = $opData[$direction]['encodingStyle'];
          $enc_style = $encodingStyle;
        }
        else {
          $enc_style = false;
        }

        // NOTE: add error handling here
        // if serializeType returns false, then catch global error and fault
        if ($parametersArrayType == 'arraySimple') {
          $p = array_shift($parameters);
          $this
            ->debug('calling serializeType w/indexed param');
          $xml .= $this
            ->serializeType($name, $type, $p, $use, $enc_style);
        }
        elseif (isset($parameters[$name])) {
          $this
            ->debug('calling serializeType w/named param');
          $xml .= $this
            ->serializeType($name, $type, $parameters[$name], $use, $enc_style);
        }
        else {

          // TODO: only send nillable
          $this
            ->debug('calling serializeType w/null param');
          $xml .= $this
            ->serializeType($name, $type, null, $use, $enc_style);
        }
      }
    }
    else {
      $this
        ->debug('no parameters passed.');
    }
  }
  $this
    ->debug("serializeParameters returning: {$xml}");
  return $xml;
}