Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SoapServer classmap object creation

Tags:

php

soapserver

I am building a web service with PHP's SoapServer class. Using the classmap feature works fine and the WSDL types are correctly mapped to the PHP types. However, I am not able to figure out how the instances of the mapped classes are created.

Is there any way to effect the creation of the object generated by the SoapServer? For example something like the __set_state magic method.

Example: I am using the xsd tytes date and datetime respectively. I want to ensure that these are converted into PHP's DateTime classes. What I do not want do to is have a downstream process which does that.

like image 273
joconja Avatar asked Jun 06 '26 07:06

joconja


1 Answers

As far as I know the proper way of doing that is the typemap option for SoapServer. Eg,

$options = array (
    'typemap' => array (
        array(
            'type_name' => 'XMLNodeForMyClass',
            'type_ns' => 'urn:localurn',
            'from_xml' => 'MyClass::fromSOAP',
            'to_xml' => 'MyClass::toSOAP'
        )
    )
);

class MyClass {
    static public function fromSOAP( string $xml ) {}
    static public function toSOAP( MyClass $Outgoing ) {}
}
like image 132
Marius Or. Avatar answered Jun 07 '26 21:06

Marius Or.