WSDL array complex type to php associative array

I've a wsdl file with this complexType:
            <complexType name="ArrayOfString">
               <complexContent>
                   <restriction base="soapenc:Array">
                      <attribute ref="soapenc:arrayType"
                      wsdl:arrayType="string[]"/>
                   </restriction>
                </complexContent>
            </complexType>
On my soap client I call soap server in this manner:
            $client = new SoapClient('marco.wsdl', array('trace' => 1,'encoding'=>'ISO-8859-1'));
            $data['user']['usr_id'] = 8;
            $data['user']['username'] = 'marco';
            $data['event'] = 'delete';
            $result =  $client->__soapCall('notify', array($data)); 
My server function log this request:

SoapServer->notify: stdClass::__set_state(array(
   'item' =>
  array (
    0 =>
    stdClass::__set_state(array(
       'key' => 'user',
       'value' =>
      stdClass::__set_state(array(
         'item' =>
        array (
          0 =>
          stdClass::__set_state(array(
             'key' => 'usr_id',
             'value' => '8',
          )),
          1 =>
          stdClass::__set_state(array(
             'key' => 'username',
             'value' => 'marco',
          )),
        ),
      )),
    )),
    1 =>
    stdClass::__set_state(array(
       'key' => 'event',
       'value' => 'delete',
    )),
  ),
))
Php map my complexType to an object!

I write this function to convert above object to an associative array:
    function getArrayFromXSDObject($map) {
        if( !isset($map->item) || empty($map->item) )
            return array();
        $ary = array();
        foreach($map->item as $obj) {
            if(is_object($obj->value)) {
                $ary[$obj->key] = $this->getArrayFromXSDObject($obj->value);
            } else {
                $ary[$obj->key] = $obj->value;
            }
        }
        return $ary;
    } 
 And now the log output is:

array (
  'user' =>
  array (
    'usr_id' => '8',
    'username' => 'marco',
  ),
  'event' => 'delete',
PS: if you want a very good library to handle SOAP and WSDL try to look at NuSOAP or any other, but NOT soap php module!



Commenti