You are here

function wsdl::serializeRPCParameters in Salesforce Suite 5

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

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

Parameters

string $operation operation name: * @param string $direction (input|output) * @param mixed $parameters parameter value(s) * @return mixed parameters serialized as XML or false on error (e.g. operation not found) * @access public

File

includes/nusoap.php, line 5013

Class

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

Code

function serializeRPCParameters($operation, $direction, $parameters) {
  $this
    ->debug("in serializeRPCParameters: 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('have ' . count($opData[$direction]['parts']) . ' part(s) to serialize');
    if (is_array($parameters)) {
      $parametersArrayType = $this
        ->isArraySimpleOrStruct($parameters);
      $this
        ->debug('have ' . count($parameters) . ' parameter(s) provided as ' . $parametersArrayType . ' to serialize');
      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("serializeRPCParameters returning: {$xml}");
  return $xml;
}