meng-tian/soap-http-binding
Composer 安装命令:
composer require meng-tian/soap-http-binding
包简介
A PHP library for binding SOAP messages to PSR-7 HTTP messages.
README 文档
README
This library binds SOAP 1.1 and SOAP 1.2 messages to PSR-7 HTTP messages.
Requirement
PHP 8.2 or newer. PHP 7.x and PHP 8.0-8.1 remain available only through older releases.
Install
composer require meng-tian/soap-http-binding:^0.4.2
Usage
HttpBinding::request embeds SOAP reqeust messages into PSR-7 HTTP requests.
use Meng\Soap\HttpBinding\HttpBinding; use Meng\Soap\HttpBinding\RequestBuilder; use Meng\Soap\Interpreter; use Laminas\Diactoros\RequestFactory; use Laminas\Diactoros\StreamFactory; $interpreter = new Interpreter('http://www.webservicex.net/airport.asmx?WSDL'); $streamFactory = new StreamFactory(); $requestFactory = new RequestFactory(); $builder = new RequestBuilder($streamFactory, $requestFactory); $httpBinding = new HttpBinding($interpreter, $builder, $streamFactory); $request = $httpBinding->request('GetAirportInformationByCountry', [['country' => 'United Kingdom']]); echo \Laminas\Diactoros\Request\Serializer::toString($request);
Output:
POST /airport.asmx HTTP/1.1
Content-Length: 322
SOAPAction: http://www.webserviceX.NET/GetAirportInformationByCountry
Content-Type: text/xml; charset="utf-8"
Host: www.webservicex.net
<?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:GetAirportInformationByCountry><ns1:country>United Kingdom</ns1:country></ns1:GetAirportInformationByCountry></SOAP-ENV:Body></SOAP-ENV:Envelope>
HttpBinding::response retrieves SOAP response messages from PSR-7 HTTP responses:
use Meng\Soap\HttpBinding\HttpBinding; use Meng\Soap\HttpBinding\RequestBuilder; use Meng\Soap\Interpreter; use Laminas\Diactoros\Response; use Laminas\Diactoros\Stream; use Laminas\Diactoros\RequestFactory; use Laminas\Diactoros\StreamFactory; $response = <<<EOD <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetAirportInformationByCountryResponse xmlns="http://www.webserviceX.NET"> <GetAirportInformationByCountryResult>some result</GetAirportInformationByCountryResult> </GetAirportInformationByCountryResponse> </soap:Body> </soap:Envelope> EOD; $stream = new Stream('php://memory', 'r+'); $stream->write($response); $stream->rewind(); $response = new Response($stream, 200, ['Content-Type' => 'text/xml; charset=utf-8']); $interpreter = new Interpreter('http://www.webservicex.net/airport.asmx?WSDL'); $streamFactory = new StreamFactory(); $requestFactory = new RequestFactory(); $builder = new RequestBuilder($streamFactory, $requestFactory); $httpBinding = new HttpBinding($interpreter, $builder, $streamFactory); $response = $httpBinding->response($response, 'GetAirportInformationByCountry'); print_r($response);
Output:
stdClass Object
(
[GetAirportInformationByCountryResult] => some result
)
This library also support SOAP 1.2 HTTP GET binding through RequestBuilder class :
use Meng\Soap\HttpBinding\RequestBuilder; use Laminas\Diactoros\RequestFactory; use Laminas\Diactoros\StreamFactory; $streamFactory = new StreamFactory(); $requestFactory = new RequestFactory(); $builder = new RequestBuilder($streamFactory, $requestFactory); $request = $builder->isSOAP12() ->setEndpoint('http://www.endpoint.com') ->setHttpMethod('GET') ->getSoapHttpRequest(); echo \Laminas\Diactoros\Request\Serializer::toString($request);
Output:
GET / HTTP/1.1
Accept: application/soap+xml
Host: www.endpoint.com
Testing
composer install vendor/bin/phpunit
License
This library is released under MIT license.
meng-tian/soap-http-binding 适用场景与选型建议
meng-tian/soap-http-binding 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.63M 次下载、GitHub Stars 达 16, 最近一次更新时间为 2016 年 02 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「soap」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 meng-tian/soap-http-binding 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 meng-tian/soap-http-binding 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 meng-tian/soap-http-binding 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
A PHP client for the Salesforce SOAP API
repository php library
Model of a web-based resource
Interfaces for web resource models and services to retrieve and create them
Interface for a factory to create Psr\Http\Message\StreamInterface objects
统计信息
- 总下载量: 2.63M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-29