meng-tian/php-soap-interpreter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

meng-tian/php-soap-interpreter

Composer 安装命令:

composer require meng-tian/php-soap-interpreter

包简介

A PHP library for interpreting SOAP messages.

关键字:

README 文档

README

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.

Prerequisite

PHP 8.2 or newer with ext-soap. PHP 7.x and PHP 8.0-8.1 remain available only through older releases.

Install

composer require meng-tian/php-soap-interpreter:^2.1

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.

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.

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:

<?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/">
<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:

/*
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:

<?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: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:

<?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>

Testing

composer install
vendor/bin/phpunit

Relevant

License

This library is released under MIT license.

meng-tian/php-soap-interpreter 适用场景与选型建议

meng-tian/php-soap-interpreter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.74M 次下载、GitHub Stars 达 21, 最近一次更新时间为 2016 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「soap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 meng-tian/php-soap-interpreter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 meng-tian/php-soap-interpreter 我们能提供哪些服务?
定制开发 / 二次开发

基于 meng-tian/php-soap-interpreter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.74M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 18
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-06