PHP code example of dmt-software / jms-soap-serializer

1. Go to this page and download the library: Download dmt-software/jms-soap-serializer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dmt-software / jms-soap-serializer example snippets


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

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

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

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

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>';

use JMS\Serializer\Serializer;

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

// $response instanceof ResponseMessage

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