You are here

function wsdl::serializeComplexTypeElements in Salesforce Suite 5.2

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

* serializes the elements for a complexType * *

Parameters

array $typeDef our internal representation of an XML schema type (or element): * @param mixed $value a native PHP value (parameter value) * @param string $ns the namespace of the type * @param string $uqType the local part of the type * @param string $use use for part (encoded|literal) * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style) * @return string value serialized as an XML string * @access private

2 calls to wsdl::serializeComplexTypeElements()
wsdl::serializeType in includes/nusoap.php
* serializes a PHP value according a given type definition * *
wsdl::serializeType in includes/nusoap.orig.php
* serializes a PHP value according a given type definition * *

File

includes/nusoap.orig.php, line 5525

Class

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

Code

function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false) {
  $xml = '';
  if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
    $this
      ->debug("in serializeComplexTypeElements, serialize elements for XML Schema type {$ns}:{$uqType}");
    if (is_array($value)) {
      $xvalue = $value;
    }
    elseif (is_object($value)) {
      $xvalue = get_object_vars($value);
    }
    else {
      $this
        ->debug("value is neither an array nor an object for XML Schema type {$ns}:{$uqType}");
      $xvalue = array();
    }

    // toggle whether all elements are present - ideally should validate against schema
    if (count($typeDef['elements']) != count($xvalue)) {
      $optionals = true;
    }
    foreach ($typeDef['elements'] as $eName => $attrs) {
      if (!isset($xvalue[$eName])) {
        if (isset($attrs['default'])) {
          $xvalue[$eName] = $attrs['default'];
          $this
            ->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
        }
      }

      // if user took advantage of a minOccurs=0, then only serialize named parameters
      if (isset($optionals) && !isset($xvalue[$eName]) && (!isset($attrs['nillable']) || $attrs['nillable'] != 'true')) {
        if (isset($attrs['minOccurs']) && $attrs['minOccurs'] != '0') {
          $this
            ->debug("apparent error: no value provided for element {$eName} with minOccurs=" . $attrs['minOccurs']);
        }

        // do nothing
        $this
          ->debug("no value provided for complexType element {$eName} and element is not nillable, so serialize nothing");
      }
      else {

        // get value
        if (isset($xvalue[$eName])) {
          $v = $xvalue[$eName];
        }
        else {
          $v = null;
        }
        if (isset($attrs['form'])) {
          $unqualified = $attrs['form'] == 'unqualified';
        }
        else {
          $unqualified = false;
        }
        if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this
          ->isArraySimpleOrStruct($v) == 'arraySimple') {
          $vv = $v;
          foreach ($vv as $k => $v) {
            if (isset($attrs['type']) || isset($attrs['ref'])) {

              // serialize schema-defined type
              $xml .= $this
                ->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
            }
            else {

              // serialize generic type (can this ever really happen?)
              $this
                ->debug("calling serialize_val() for {$v}, {$eName}, false, false, false, false, {$use}");
              $xml .= $this
                ->serialize_val($v, $eName, false, false, false, false, $use);
            }
          }
        }
        else {
          if (isset($attrs['type']) || isset($attrs['ref'])) {

            // serialize schema-defined type
            $xml .= $this
              ->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
          }
          else {

            // serialize generic type (can this ever really happen?)
            $this
              ->debug("calling serialize_val() for {$v}, {$eName}, false, false, false, false, {$use}");
            $xml .= $this
              ->serialize_val($v, $eName, false, false, false, false, $use);
          }
        }
      }
    }
  }
  else {
    $this
      ->debug("no elements to serialize for XML Schema type {$ns}:{$uqType}");
  }
  if (isset($typeDef['extensionBase'])) {
    $ns = $this
      ->getPrefix($typeDef['extensionBase']);
    $uqType = $this
      ->getLocalPart($typeDef['extensionBase']);
    if ($this
      ->getNamespaceFromPrefix($ns)) {
      $ns = $this
        ->getNamespaceFromPrefix($ns);
    }
    if ($typeDef = $this
      ->getTypeDef($uqType, $ns)) {
      $this
        ->debug("serialize elements for extension base {$ns}:{$uqType}");
      $xml .= $this
        ->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
    }
    else {
      $this
        ->debug("extension base {$ns}:{$uqType} is not a supported type");
    }
  }
  return $xml;
}