Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't make anyType to work with soap-client #56

Open
Toilal opened this issue Aug 24, 2020 · 1 comment
Open

Can't make anyType to work with soap-client #56

Toilal opened this issue Aug 24, 2020 · 1 comment

Comments

@Toilal
Copy link
Contributor

Toilal commented Aug 24, 2020

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
Copy link
Contributor Author

Toilal commented Aug 24, 2020

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant