php2wsdl icon indicating copy to clipboard operation
php2wsdl copied to clipboard

Creating complex type of an array of basic data types

Open Schaumbaum opened this issue 11 years ago • 6 comments

Hi Dragos,

sorry for opening a new issue, but I don't found your contact email, otherwise I had contacted you directly. First, thanks for your fast support. Unfortunately your changes don't work for my scenario. Now arrays of basic data types are not resulting in complex types anymore, as they are handled as basic array.

<message name="testMethodIn">
    <part name="para1" type="soap-enc:Array"/>
    <part name="para2" type="soap-enc:Array"/>
</message>
<message name="testMethodOut">
    <part name="return" type="soap-enc:Array"/>
</message>

That's ok for php and his dynamic typing, but are more strict languages would like to know what data type is stored within the array.

My corresponding method for this example:

     /**
     * @param string[] $para1
     * @param bool[] $para2
     * @return string[]
     */
    public function testMethod($para1, $para2){
        return array("ret1","ret2");
    }

I think the resulting wsdl parts It should look something like that:

  1. the data definition
<xsd:complexType name="ArrayOfString">
    <xsd:complexContent>
        <xsd:restriction base="soap-enc:Array">
            <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="xsd:string[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ArrayOfBool">
    <xsd:complexContent>
        <xsd:restriction base="soap-enc:Array">
            <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="xsd:bool[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>
  1. the message definitions
<message name="testMethodIn">
    <part name="para1" type="tns:ArrayOfString"/>
    <part name="para2" type="tns:ArrayOfBool"/>
</message>
<message name="testMethodOut">
    <part name="return" type="tns:ArrayOfString"/>
</message>

I have changed the addComplexTypeArray method to achieve this.

protected function addComplexTypeArray($singularType, $type)
    {
        $isBasicDataType = isset(self::$XSDTypes[strtolower($singularType)]);
        $nsPrefix = $isBasicDataType ? 'xsd' : 'tns';

        $xsdComplexTypeName = 'ArrayOf' . ucfirst(static::typeToQName($singularType));
        $xsdComplexType = 'tns:' . $xsdComplexTypeName;

        // Register type here to avoid recursion.
        $this->addType($type, $xsdComplexType);

        // Process singular type using DefaultComplexType strategy.
        if(!$isBasicDataType){
            $this->addComplexType($singularType);
        }

        // Add array type structure to WSDL document.
        $complexType = $this->dom->createElement('xsd:complexType');
        $complexType->setAttribute('name', $xsdComplexTypeName);

        $complexContent = $this->dom->createElement('xsd:complexContent');
        $complexType->appendChild($complexContent);

        $xsdRestriction = $this->dom->createElement('xsd:restriction');
        $xsdRestriction->setAttribute('base', 'soap-enc:Array');
        $complexContent->appendChild($xsdRestriction);

        $xsdAttribute = $this->dom->createElement('xsd:attribute');
        $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType');
        $xsdAttribute->setAttribute('wsdl:arrayType', $nsPrefix.':' . static::typeToQName($singularType) . '[]');
        $xsdRestriction->appendChild($xsdAttribute);

        $this->schema->appendChild($complexType);

        return $xsdComplexType;
    }

Hopefully it also works as desired with objects. If you have any example for an object, that is not working properly with this changes feel free to inform me.

Schaumbaum avatar Nov 30 '14 14:11 Schaumbaum

Hi,

you are right, array of scalars will be described as basic data types.

Can you can modify the code, change the tests as a pull request ?

dragosprotung avatar Dec 01 '14 11:12 dragosprotung

Sure, I hope to get the time this week.

Schaumbaum avatar Dec 02 '14 09:12 Schaumbaum

@Schaumbaum Any progress ?

dragosprotung avatar Mar 03 '15 22:03 dragosprotung

Sure, I hope to get the time this week. @Schaumbaum any progress? Do you have a branch with anything you do?

mstrey avatar Jun 30 '20 20:06 mstrey

is this issue solved? I am trying to find out if array and complex types work.

ekrellw avatar Nov 13 '21 11:11 ekrellw

I am willing to take whatever has been written and finish it in order to have support of complex types and arrays and optional fields (like minOccurs="0" maxOccurs="1")

ekrellw avatar Nov 24 '21 12:11 ekrellw