vaclavvanik / soap-interpreter
解析 SOAP 1.1 和 SOAP 1.2 消息
1.0.0
2022-12-06 09:49 UTC
Requires
- php: ^7.3 || ^8.0
- ext-soap: *
- vaclavvanik/soap-wsdl: ^1.0.0
README
此包提供 SOAP 1.1 和 SOAP 1.2 消息的解析。它可以在 WSDL 或非 WSDL 模式下使用。实现基于 PHP 的 SoapClient。
不建议直接使用此包。
您可以使用
-
soap-binding 包创建符合 PSR-7 规范的 SOAP 请求,并处理 SOAP 的 PSR-7 响应。
-
soap-client 包使用 PSR HTTP 客户端处理请求和响应。
安装
您可以通过 composer 安装此包。
composer require vaclavvanik/soap-interpreter
使用方法
PhpInterpreter 负责生成 SOAP 请求 消息,并翻译 SOAP 响应 消息。
在 WSDL 模式下创建 PhpInterpreter
<?php declare(strict_types=1); use VaclavVanik\Soap\Interpreter\PhpInterpreter; $interpreter = PhpInterpreter::fromWsdl('http://www.dneonline.com/calculator.asmx?wsdl');
在非 WSDL 模式下创建 PhpInterpreter
<?php declare(strict_types=1); use VaclavVanik\Soap\Interpreter\PhpInterpreter; $interpreter = PhpInterpreter::fromNonWsdl('http://tempuri.org/', 'http://www.dneonline.com/calculator.asmx');
在 WSDL 模式下生成 SOAP 请求消息
<?php declare(strict_types=1); use VaclavVanik\Soap\Interpreter\PhpInterpreter; $request = (PhpInterpreter::fromWsdl('http://www.dneonline.com/calculator.asmx?wsdl'))->request('Add', ['Add' => ['intA' => 1, 'intB' => 3]]); print_r($request->getBody());
输出
<?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>
翻译 SOAP 响应消息
<?php declare(strict_types=1); use VaclavVanik\Soap\Interpreter\PhpInterpreter; $response = <<<XML <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <ns1:AddResponse xmlns:ns1="http://tempuri.org/"> <ns1:AddResult>4</ns1:AddResult> </ns1:AddResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> XML; $response = (PhpInterpreter::fromWsdl('http://www.dneonline.com/calculator.asmx?wsdl'))->response('Add', $response); print_r($response->getResult());
输出
stdClass Object ( [AddResult] => 4 )
高级 WSDL 使用
包 soap-interpreter-wsdl 提供高级 WSDL 使用。
异常
- Exception\SoapFault 如果抛出 SOAP 错误。
- Exception\ValueError 如果必要的参数不正确。
- Exception\WsdlParsingError 如果 wsdl 无法解析。
- Exception\Exception 如果发生其他错误。
或 VaclavVanik\Soap\Wsdl\Exception\Exception
如果发生其他 wsdl 错误。
运行检查 - 编码规范和 php-unit
安装依赖
make install
运行检查
make check
变更日志
请参阅CHANGELOG 了解最近更改的更多信息。
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。