soap-client icon indicating copy to clipboard operation
soap-client copied to clipboard

Can't make anyType to work with soap-client

Open Toilal opened this issue 4 years ago • 1 comments

I'm consuming a Soap server that has some fields declared as xs:anyType.

There's a note in xsd2php README.md about how to declare custom handlers for those types, but I can't get them to work with soap-client.

Could you provide a short example to make it work ? How to register a custom JMS Serializer handler inside soap client container ?

Toilal avatar Aug 24 '20 14:08 Toilal

I ended up to write this handler

class SerializerMixedSubscribingHandler implements SubscribingHandlerInterface

{
    public static function getSubscribingMethods()
    {
        return array(
            array(
                'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION,
                'format' => 'xml',
                'type' => 'mixed',
                'method' => 'deserializeMixedType'
            ),
            array(
                'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
                'format' => 'xml',
                'type' => 'mixed',
                'method' => 'serializeMixedType'
            )
        );
    }

    public function serializeMixedType(XmlSerializationVisitor $visitor, $data, array $type, Context $context)
    {
        return $visitor->visitSimpleString(strval($data), $type);
    }

    public function deserializeMixedType(XmlDeserializationVisitor $visitor, $data, array $type)
    {
        return strval($visitor->getResult($data));
    }
}

And registered in when creating the soap client, by using the callback function.

        $serializer = SoapContainerBuilder::createSerializerBuilderFromContainer($container, function ($handler) {
            /** @var HandlerRegistryInterface $handler */
            $handler->registerSubscribingHandler(new SerializerMixedSubscribingHandler());
        }, $projectDir)
            ->build();

Toilal avatar Aug 24 '20 15:08 Toilal