PHP code example of php-soap / ext-soap-engine

1. Go to this page and download the library: Download php-soap/ext-soap-engine 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/ */

    

php-soap / ext-soap-engine example snippets


use Soap\Engine\SimpleEngine;
use Soap\ExtSoapEngine\AbusedClient;
use Soap\ExtSoapEngine\Configuration\ClassMap\ClassMapCollection;
use Soap\ExtSoapEngine\Configuration\TypeConverter\TypeConverterCollection;
use Soap\ExtSoapEngine\ExtSoapDriver;
use Soap\ExtSoapEngine\ExtSoapOptions;
use Soap\ExtSoapEngine\Transport\ExtSoapClientTransport;
use Soap\ExtSoapEngine\Transport\TraceableTransport;

$engine = new SimpleEngine(
    ExtSoapDriver::createFromClient(
        $client = AbusedClient::createFromOptions(
            ExtSoapOptions::defaults($wsdl, [
                'soap_version' => SOAP_1_2,
            ])
                ->disableWsdlCache()
                ->withClassMap(new ClassMapCollection())
                ->withTypeMap(new TypeConverterCollection())
        )
    ),
    $transport = new TraceableTransport(
        $client,
        new ExtSoapClientTransport($client)
    )
);

$result = $engine->request('SomeMethod', [(object)['param1' => true]]);

// Collecting last soap call:
var_dump($transport->collectLastRequestInfo());

$client->__setLocation(...);
$client->__setSoapHeaders(...);
$client->__setCookie(...);

var_dump(
    $engine->getMetadata()->getMethods(),
    $engine->getMetadata()->getTypes()
);

$methodInfo = $engine->getMetadata()->getMethods()->fetchByName('SomeMethod');



use Soap\ExtSoapEngine\ExtSoapOptions;
use Soap\ExtSoapEngine\Wsdl\Naming\Md5Strategy;use Soap\ExtSoapEngine\Wsdl\TemporaryWsdlLoaderProvider;
use Soap\Psr18Transport\Wsdl\Psr18Loader;
use Soap\Wsdl\Loader\FlatteningLoader;

$options = ExtSoapOptions::defaults($wsdl, ['location' => 'http://somedifferentserver.com'])
    ->disableWsdlCache()
    ->withClassMap(\MyClassMap::getCollection())
    ->withWsdlProvider(new TemporaryWsdlLoaderProvider(
        new FlatteningLoader(new Psr18Loader($httpClient)),
        new Md5Strategy(),
        'some/dir'
    ));

$typemap = $options->getTypeMap();
$typemap->add(new \MyTypeConverter());

use Soap\ExtSoapEngine\ExtSoapOptions;

$options = ExtSoapOptions::defaults($wsdl)
    ->withWsdlProvider($yourProvider);


use Soap\ExtSoapEngine\Wsdl\InMemoryWsdlProvider;

$provider = new InMemoryWsdlProvider();
$wsdl = ($provider)('<definitions ..... />');


use Soap\ExtSoapEngine\Wsdl\PassThroughWsdlProvider;

$provider = new PassThroughWsdlProvider();
$wsdl = ($provider)('some.wsdl');


use Soap\ExtSoapEngine\Wsdl\Naming\Md5Strategy;
use Soap\ExtSoapEngine\Wsdl\PermanentWsdlLoaderProvider;
use Soap\Wsdl\Loader\FlatteningLoader;
use Soap\Wsdl\Loader\StreamWrapperLoader;

$provider = new PermanentWsdlLoaderProvider(
    new FlatteningLoader(new StreamWrapperLoader()),
    new Md5Strategy(),
    'target/location'
);

// Force downloads:
$provider = $provider->forceDownload();

$wsdl = ($provider)('some.wsdl');


use Soap\ExtSoapEngine\Wsdl\Naming\Md5Strategy;
use Soap\ExtSoapEngine\Wsdl\TemporaryWsdlLoaderProvider;
use Soap\Wsdl\Loader\FlatteningLoader;
use Soap\Wsdl\Loader\StreamWrapperLoader;

$provider = new TemporaryWsdlLoaderProvider(
    new FlatteningLoader(new StreamWrapperLoader()),
    new Md5Strategy(),
    'target/location'
);

$wsdl = ($provider)('some.wsdl');

namespace Soap\ExtSoapEngine\Wsdl;

interface WsdlProvider
{
    /**
     * This method can be used to transform a location into another location.
     * The output needs to be processable by the SoapClient $wsdl option.
     */
    public function __invoke(string $location): string;
}

use Soap\ExtSoapEngine\Configuration\ClassMap\ClassMap;
use Soap\ExtSoapEngine\ExtSoapOptions;

$options = ExtSoapOptions::defaults($wsdl);
$classmap = $options->getClassMap();
$classmap->set(new ClassMap('WsdlType', 'PhpClassName'));

use Soap\ExtSoapEngine\Configuration\TypeConverter;
use Soap\ExtSoapEngine\ExtSoapOptions;

$options = ExtSoapOptions::defaults($wsdl);
$typemap = $options->getTypeMap();
$typemap->add(new TypeCOnverter\DateTimeTypeConverter());
$typemap->add(new TypeConverter\DecimalTypeConverter());
$typemap->add(new TypeConverter\DoubleTypeConverter());