Coder Social home page Coder Social logo

jms-soap-serializer's Introduction

SOAP Serializer

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

Install

composer require dmt-software/jms-soap-serializer

Usage

Configure Serializer

use DMT\Soap\Serializer\SoapDeserializationVisitorFactory;
use DMT\Soap\Serializer\SoapSerializationVisitorFactory;
use DMT\Soap\Serializer\SoapMessageEventSubscriber;
use JMS\Serializer\EventDispatcher\EventDispatcher;
use JMS\Serializer\SerializerBuilder;
 
$builder = SerializerBuilder::create()
    ->setSerializationVisitor('soap', new SoapSerializationVisitorFactory())
    ->setDeserializationVisitor('soap', new SoapDeserializationVisitorFactory())
    ->configureListeners(
        function (EventDispatcher $dispatcher) {
            $dispatcher->addSubscriber(
                new SoapMessageEventSubscriber()
            );
        }
    );

$serializer = $builder->build();

Enable (de)serialization of DateTime objects

use DMT\Soap\Serializer\SoapDateHandler;
use JMS\Serializer\Handler\HandlerRegistry;

/** @var JMS\Serializer\SerializerBuilder $builder */
$builder->configureHandlers(
    function(HandlerRegistry $registry) {
        $registry->registerSubscribingHandler(new SoapDateHandler());
    }
);

Configure Serializer with SoapHeader

use DMT\Soap\Serializer\SoapHeaderInterface;
use DMT\Soap\Serializer\SoapHeaderEventSubscriber;
use DMT\Soap\Serializer\SoapMessageEventSubscriber;
use JMS\Serializer\EventDispatcher\EventDispatcher;
 
/** @var JMS\Serializer\SerializerBuilder $builder */
$builder->configureListeners(
    function (EventDispatcher $dispatcher) {
        $dispatcher->addSubscriber(
            new SoapMessageEventSubscriber()
        );
        /** @var SoapHeaderInterface $soapHeader */
        $dispatcher->addSubscriber(
            new SoapHeaderEventSubscriber($soapHeader)
        );
    }
);

Using SOAP 1.2

use DMT\Soap\Serializer\SoapNamespaceInterface;
use DMT\Soap\Serializer\SoapSerializationVisitorFactory;

/** @var JMS\Serializer\SerializerBuilder $builder */
$builder->setSerializationVisitor(
    'soap',
    (new SoapSerializationVisitorFactory())
        ->setSoapVersion(SoapNamespaceInterface::SOAP_1_2)
);

Using Serializer

Serialize SOAP Request

use JMS\Serializer\Serializer;

/** @var Message $requestMessage */
/** @var Serializer $serializer */
$request = $serializer->serialize($requestMessage, 'soap');

// $request = '<soap:Envelope ...><soap:Body><ns1:Message>...</ns1:Message></soap:Body></soap:Envelope>';

Deserialize SOAP Response

use JMS\Serializer\Serializer;

/** @var Serializer $serializer */
$response = $serializer->deserialize('<env:Envelope ... </env:Envelope>', ResponseMessage::class, 'soap');

// $response instanceof ResponseMessage

Debugging

Failing to make a request

When creating a SOAP message you must provide a XmlRoot and XmlRootNamespace. If you forgot to provide them an exception is thrown:

Missing XmlRootName or XmlRootNamespace for {{ YourSOAPRequest }}.

To fix this, add the XmlRoot annotation to your configuration:

namespace Any\NS; 
 
use JMS\Serializer\Annotation as JMS;
 
/** 
 * @JMS\XmlRoot("YourSOAPRequest", namespace="http://ns-for-your-request")
 */
class YourSOAPRequest
{
    //...
}

or if you're using yaml configuration:

Any\NS\YourSOAPRequest:
  ...
  xml_root_name: YourSOAPRequest
  xml_root_namespace: http://ns-for-your-request
  ...   

jms-soap-serializer's People

Contributors

karlerss avatar proggeler avatar seriyyy95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jms-soap-serializer's Issues

Serialization fails when SoapHeader is used

The soap header event should only be called when the body serialization is finished.
It does not right now, appending data to the header that should be in the body message.

Support PHP 8.1

SoapFault initialization/deserialization is changed 7.4 -> 8.1, missing properties are now just empty and not missing.

Compatibility error

Since PHP 7.0, functions inspecting arguments, like func_get_args(), no longer report the original value as passed to a parameter, but will instead provide the current value. The parameter "$code" was changed on line 52

PHP 5.6

I think this project is a great idea.

Is it possible to do the same with php 5.6?

Our project uses an old version of jms / serializer therefore we don't have DeserializationVisitorFactory.

In this case is it possible that we can implement our own visitor the same?

camelCase

Hello,

I'm trying to get your Soap Serializer to work with my webservice but I'm having some problems with it :-(

I am trying to get the following envelope:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://domain.com">
SOAP-ENV:Body
ns1:searchRequest
ns1:querymy query goes here.</ns1:query>
....

But at the moment all the tags are changed to lowercase :-/

<soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
soap:body

Is this by design or am I just missing some little configuration?

Regards - Lars Hansen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.