2017 © Pedro Peláez
 

library php-soap-interpreter

A PHP library for interpreting SOAP messages.

image

meng-tian/php-soap-interpreter

A PHP library for interpreting SOAP messages.

  • Saturday, May 21, 2016
  • by meng-tian
  • Repository
  • 1 Watchers
  • 9 Stars
  • 156,979 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 6 Versions
  • 19 % Grown

The README.md

PHP SOAP Interpreter codecov.io workflow

A PHP library for interpreting SOAP 1.1 and SOAP 1.2 messages. It can be used in WSDL or non-WSDL mode. The implementation is built on the top of PHP's SoapClient., (*1)

Prerequisite

PHP 7.1 --enablelibxml --enable-soap, (*2)

Install

composer require meng-tian/php-soap-interpreter

Usage

An Interpreter is responsible for generating SOAP request messages and translating SOAP response messages. The constructor of Interpreter class is the same as SoapClient. The first parameter is wsdl, the second parameter is an array of options., (*3)

It should be noted that not all options supported by SoapClient are supported by Interpreter. The supported options of Interpreter are: location, uri, style, use, soap_version, encoding, exceptions, classmap, typemap, cache_wsdl and features. More detailed explanations of those options can be found in SoapClient::SoapClient. The unsupported options are related to debugging or HTTP transport, which are not the intended responsibility of Interpreter., (*4)

Basic Examples

Generate SOAP request message in WSDL mode
$interpreter = new Interpreter('http://www.webservicex.net/length.asmx?WSDL');
$request = $interpreter->request(
    'ChangeLengthUnit',
    [['LengthValue'=>'1', 'fromLengthUnit'=>'Inches', 'toLengthUnit'=>'Meters']]
);

print_r($request->getSoapMessage());

Output:, (*5)


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.webserviceX.NET/">
<SOAP-ENV:Body><ns1:ChangeLengthUnit><ns1:LengthValue>1</ns1:LengthValue><ns1:fromLengthUnit>Inches</ns1:fromLengthUnit><ns1:toLengthUnit>Meters</ns1:toLengthUnit></ns1:ChangeLengthUnit></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Translate SOAP response message
$interpreter = new Interpreter('http://www.webservicex.net/length.asmx?WSDL');
$response = <<<EOD
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <ChangeLengthUnitResponse xmlns="http://www.webserviceX.NET/">
            <ChangeLengthUnitResult>0.025400000000000002</ChangeLengthUnitResult>
        </ChangeLengthUnitResponse>
    </soap:Body>
</soap:Envelope>
EOD;
$response = $interpreter->response($response, 'ChangeLengthUnit');

print_r($response);

Output:, (*6)

/*
Output:
stdClass Object
(
    [ChangeLengthUnitResult] => 0.0254
)
*/

Advanced Examples

Generate SOAP request message in non-WSDL mode
// In non-WSDL mode, location and uri must be provided as they are required by SoapClient.
$interpreter = new Interpreter(null, ['location'=>'http://www.webservicex.net/length.asmx', 'uri'=>'http://www.webserviceX.NET/']);
$request = $interpreter->request(
    'ChangeLengthUnit',
    [
        new SoapParam('1', 'ns1:LengthValue'),
        new SoapParam('Inches', 'ns1:fromLengthUnit'),
        new SoapParam('Meters', 'ns1:toLengthUnit')
    ],
    ['soapaction'=>'http://www.webserviceX.NET/ChangeLengthUnit']
);

print_r($request->getSoapMessage());

Output:, (*7)


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.webserviceX.NET/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:ChangeLengthUnit><ns1:LengthValue xsi:type="xsd:string">1</ns1:LengthValue><ns1:fromLengthUnit xsi:type="xsd:string">Inches</ns1:fromLengthUnit><ns1:toLengthUnit xsi:type="xsd:string">Meters</ns1:toLengthUnit></ns1:ChangeLengthUnit></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP input headers
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
$request = $interpreter->request('ConversionRate', [['FromCurrency' => 'AFA', 'ToCurrency' => 'ALL']], null, [new SoapHeader('www.namespace.com', 'test_header', 'header_data')]);
print_r($request->getSoapMessage());

Output:, (*8)

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.webserviceX.NET/" xmlns:ns2="www.namespace.com">
<SOAP-ENV:Header><ns2:test_header>header_data</ns2:test_header></SOAP-ENV:Header>
<SOAP-ENV:Body><ns1:ConversionRate><ns1:FromCurrency>AFA</ns1:FromCurrency><ns1:ToCurrency>ALL</ns1:ToCurrency></ns1:ConversionRate></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP output headers

TODO, (*9)

Class map

TODO, (*10)

Type map

TODO, (*11)

Relevant

License

This library is released under MIT license., (*12)

The Versions

21/05 2016

dev-master

9999999-dev

A PHP library for interpreting SOAP messages.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Meng Tian

soap

21/05 2016

1.0.2

1.0.2.0

A PHP library for interpreting SOAP messages.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Meng Tian

soap

31/03 2016

1.0.1

1.0.1.0

A PHP library for interpreting SOAP messages.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Meng Tian

soap

26/02 2016

1.0.0

1.0.0.0

A PHP library for interpreting SOAP messages.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Meng Tian

soap

24/02 2016

0.2.0

0.2.0.0

A PHP library for interpreting SOAP envelopes.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Meng Tian

08/02 2016

0.1.0

0.1.0.0

A PHP library for interpreting SOAP envelopes.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Meng Tian