This package provides binding SOAP messages to PSR-7 HTTP messages. The main purpose of this library is to use it together with PSR-18 HTTP Client.
You can install this package via composer.
composer require vaclavvanik/soap-binding
This package needs PSR-17 HTTP Factories implementation. You can use e.g. Laminas Diactoros.
composer require vaclavvanik/soap-binding laminas/laminas-diactoros
Binding::request() embeds SOAP request messages into PSR-7 HTTP requests.
<?php
declare(strict_types=1);
use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\Request\Serializer;
use Laminas\Diactoros\StreamFactory;
use VaclavVanik\Soap\Binding\InterpreterBinding;
use VaclavVanik\Soap\Binding\PsrRequestFactory;
use VaclavVanik\Soap\Interpreter\PhpInterpreter;
$factory = new PsrRequestFactory(new RequestFactory(), new StreamFactory());
$interpreter = PhpInterpreter::fromWsdl('http://www.dneonline.com/calculator.asmx?wsdl');
$httpBinding = new InterpreterBinding($interpreter, $factory);
$psrRequest = $httpBinding->request('Add', ['Add' => ['intA' => 1, 'intB' => 3]]);
echo Serializer::toString($psrRequest);
Output:
POST /calculator.asmx HTTP/1.1
SOAPAction: http://tempuri.org/Add
Content-Type: text/xml; charset="utf-8"
Host: www.dneonline.com
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:Add>
<ns1:intA>1</ns1:intA>
<ns1:intB>3</ns1:intB>
</ns1:Add>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Binding::response() embeds PSR-7 HTTP response into SOAP response object.
Send $psrRequest
created above with any PSR HTTP Client and get SOAP response.
<?php
//$psrResponse = $client->sendRequest($psrRequest);
$result = $httpBinding->response('Add', $psrResponse);
print_r($result->getResult());
Output:
stdClass Object
(
[AddResult] => 4
)
- Exception\FaultRequest if error thrown during processing request.
- Exception\FaultResponse if error thrown during processing response.
- Exception\ValueError if required argument is incorrect.
Install dependencies:
make install
Run check:
make check
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.