WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
422 stars 73 forks source link

Option to prefix enums and structs by operation name #247

Open rauanmayemir opened 3 years ago

rauanmayemir commented 3 years ago

Is your feature request related to a problem? Please describe.

It's both a bug and a feature request to resolve it.

WSDL operations can use same element names with different types. It's a normal practice because operations can use different types. But in WsdlToPhp structs are created by name and elements with name clashes are not handled in any way. If there's an already existing struct, WsdlToPhp thinks it's already been created.

If I have two WSDL operations with same name, one will work incorrectly.

Describe the solution you'd like

A simple way to resolve this would be allowing to prefix structs and enums with an operation name (similar to what could be done for services with gather method).

This could lead to a lot of meaningless duplication, so I think WsdlToPhp could be smarter in dealing with duplication by also checking the type of the element, not just name. Then, if it's a different element with same name, it could prefix or suffix it with the operation name to avoid name clashes.

Describe alternatives you've considered

More correct way would be creating elements in sub-namespaces like so:

VendorName\StructType\CreateObjectRequest
VendorName\StructType\UpdateObjectRequest
VendorName\StructType\CreateObjectRequest\Payload //  wraps ObjectDataForCreate
VendorName\StructType\UpdateObjectRequest\Payload // wraps ObjectDataForUpdate
VendorName\StructType\ObjectDataForCreate
VendorName\StructType\ObjectDataForUpdate
mikaelcom commented 3 years ago

I think it is similar to the issue https://github.com/WsdlToPhp/PackageGenerator/issues/214.

Having two structs named identically but having a different signature is complex to handle. The native SoapClient class allows to map PHP class to SOAP structs and only one PHP class can be mapped to a Struct name, classmap option. So differentiating classes based on SOAP namespace would break the mapping from SOAP response to PHP object for the structs that are duplicated by the name.

Is it possible that the "two WSDL operations with same name" are declared for different ports (which would mean their goal is the same)? Or is there goal different (which would be confusing)?

Namespacing classes based on their usage would lead to lots of generation changes potentially, meaning the PHP namespaces and class content.

Let me know if I well understood your feedback and if my thought are not fully true. Having the WSDL could be helping.

rauanmayemir commented 3 years ago

I don't think they're in different ports. Here's an example wsdl.

The part that has name clashes (at least one that I discovered yet) is in UploadAwpRequest/awpInfoList/awpInfo (type is "ns1:AwpUploadInfo") and AwpQueryUpdatesResponse/awpInfoList/awpInfo (type is "ns1:AwpInfo").