3

I create a complete pluggin in Wordpress using ZendFramework and now i'd like to expose a webservice to access the data because i need to create a c# importation application.

The problem i'm facing is that even though i set the type of a webservice return to a specific type, the classmap is not kicking in and transforming the type. For example:

/**
 * Retursn all events registered on the sgm web interface
 * 
 * @return models_event[]
 */
public function getAllEvents(){
    return models_event::getEvents();
}

defines that the class returned in a models_event array. If i launch the WSDL section, i get a complex type added as "models_event" but heres what's wrong:

    $autodiscover = new Zend_Soap_AutoDiscover(array(
        'classmap' => array(
            'event' => "models_event",
        ),
        'encoding' => 'utf-8'
    ));
    $autodiscover->setComplexTypeStrategy(new Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex());
    $autodiscover->setClass('models_webservice');
    $autodiscover->handle();

I class mapped models_event to event. So my WSDL should export the complex type:

<xsd:complexType name="ArrayOfmodels_event">
    <xsd:complexContent>
        <xsd:restriction base="soap-enc:Array">
            <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="tns:models_event[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="models_event">
    <xsd:all/>
</xsd:complexType>

But as you can see it is returning a models_event[] complexe type and models_event complex type... i'm all messed up... Why is it doing this?

Mathieu Dumoulin
  • 12,126
  • 7
  • 43
  • 71

1 Answers1

2

What version of Zend Framework are you working with?

In the version that I'm looking at (1.11.10), Zend_Soap_AutoDiscover does not take an array of options as one of the constructor arguments. The method signature for the constructor is as follows:

    public function __construct($strategy = true, $uri=null, $wsdlClass=null)

The classmap option you are referring to is in Zend_Soap_Server and, IMO, exists mainly because Zend_Soap_Server is mostly just a wrapper around PHP's native SoapServer class, so it's interface allows you to access all of the options that are provided by the underlying class. I'm also guessing that that the classmap option exists in order to solve a slightly different problem, which is where you are building a SOAP server based on pre-existing WSDL and would like to map WSDL names to internal PHP class names.

My advice would simply be to rename the models_event class to event (or, better still, Event), which will hopefully get you closer to what you are looking for in the WSDL.

JamesG
  • 4,288
  • 2
  • 31
  • 36
  • Thanks for the answer but i can't rename the class because it's part of my autoloading strategy using Zend Autoloader. Regarding the class map there has to be a way to pass on to the autodiscovery because then the WSDL wouldn't match the classes returned by the server. I'm not saying you're wrong but there is definitely something we are missing here... – Mathieu Dumoulin Jan 27 '12 at 12:45
  • I understand what you are saying about not being able to rename the class. In my implementation I have a controller implemented in the proper Zend MVC style but it uses `require_once()` to drag in the class that is used in the call to `setClass()`. – JamesG Jan 29 '12 at 22:28
  • 1
    I also meant to add that the `AutoDiscover` class only seems to work purely off the actual classes or functions that you provide it. For example, the `setClass()` method seems to just use reflection to work out the contents of the WSDL. There does not appear to be any facility that would allow the mapping of names from the method names in your class to some arbitrary set of function names. So I think that renaming your class and dragging it in manually using `require_once()` might be your only option. Or you could add the class mapping ability to `Zend_Soap_AutoDiscover`. :-) – JamesG Jan 29 '12 at 22:32