vaclavvanik / soap-binding
将SOAP消息绑定到PSR-7 HTTP消息
0.3.0
2022-12-01 15:27 UTC
Requires
- php: ^7.3 || ^8.0
- ext-soap: *
- psr/http-factory: ^1.0.1
- psr/http-message: ^1.0.0
- vaclavvanik/soap-interpreter: ^0.4.0
This package is auto-updated.
Last update: 2024-09-29 06:20:23 UTC
README
此包提供将SOAP消息绑定到PSR-7 HTTP消息的功能。该库的主要目的是与PSR-18 HTTP客户端一起使用。
安装
您可以通过composer安装此包。
composer require vaclavvanik/soap-binding
此包需要PSR-17 HTTP Factories实现。例如,您可以使用Laminas Diactoros。
composer require vaclavvanik/soap-binding laminas/laminas-diactoros
使用方法
Binding::request()将SOAP请求消息嵌入到PSR-7 HTTP请求中。
<?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);
输出
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()将PSR-7 HTTP响应嵌入到SOAP响应对象中。
使用上述创建的任何PSR HTTP客户端发送$psrRequest并获取SOAP响应。
<?php //$psrResponse = $client->sendRequest($psrRequest); $result = $httpBinding->response('Add', $psrResponse); print_r($result->getResult());
输出
stdClass Object ( [AddResult] => 4 )
异常
- Exception\FaultRequest如果在处理请求期间抛出错误。
- Exception\FaultResponse如果在处理响应期间抛出错误。
- Exception\ValueError如果必需的参数不正确。
运行检查 - 编码规范和php-unit
安装依赖项
make install
运行检查
make check
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
许可
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。