tuscanicz/soap
Composer 安装命令:
composer require tuscanicz/soap
包简介
A largely refactored besimple/soap used to build SOAP and WSDL based web services. This fork fixes a lot of errors and provides better API, robust, stable and modern codebase.
README 文档
README
Build SOAP and WSDL based web services. This fork is a refactored version that fixes a lot of errors and provides better API, robust, stable and modern codebase. See How to use that will help you to understand the magic.
Components
BeSimpleSoap consists of five components ...
BeSimpleSoapClient
Refactored BeSimpleSoapClient is a component that extends the native PHP SoapClient with further features like SwA and WS-Security.
BeSimpleSoapServer
Refactored BeSimpleSoapServer is a component that extends the native PHP SoapServer with further features like SwA and WS-Security.
BeSimpleSoapCommon
Refactored BeSimpleSoapCommon component contains functionality shared by both the server and client implementations.
BeSimpleSoapWsdl
Untouched! The component is not affected by refactoring so it should work properly. For further information see the original README.
BeSimpleSoapBundle
Unsupported! The BeSimpleSoapBundle is a Symfony2 bundle to build WSDL and SOAP based web services. For further information see the the original README. Will not work since the Symfony libraries were removed and usages of other components were not refactored. Feel free to fork this repository and fix it!
Installation
If you do not yet have composer, install it like this:
curl -s http://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin
Create a composer.json file:
{
"require": {
"tuscanicz/soap": "^4.2"
}
}
Now you are ready to install the library:
php /usr/local/bin/composer.phar install
How to use
You can investigate the unit tests dir tests in order to get a clue.
Forget about associative arrays, vague configurations, multiple extension and silent errors!
This may look a bit more complex at the first sight,
but it will guide you to configure and set up your client or server properly.
Example of soap client call
$soapClientBuilder = new SoapClientBuilder(); $soapClient = $soapClientBuilder->build( SoapClientOptionsBuilder::createWithDefaults(), SoapOptionsBuilder::createWithDefaults('http://path/to/wsdlfile.wsdl') ); $myRequest = new MyRequest(); $myRequest->attribute = 'string value'; $soapResponse = $soapClient->soapCall('myMethod', [$myRequest]); var_dump($soapResponse); // Contains Response, Attachments
Something wrong?!
Turn on the tracking and catch SoapFaultWithTracingData exception to get some sweets :)
try { $soapResponse = $soapClient->soapCall('myMethod', [$myRequest]); } catch (SoapFaultWithTracingData $fault) { var_dump($fault->getSoapResponseTracingData()->getLastRequest()); }
In this example, a MyRequest object has been used to describe request.
Using a ClassMap, you help SoapClient to turn it into XML request.
Example of soap server handling
Starting a SOAP server is a bit more complex. I recommend you to inspect SoapServer unit tests for inspiration.
$dummyService = new DummyService(); $classMap = new ClassMap(); foreach ($dummyService->getClassMap() as $type => $className) { $classMap->add($type, $className); } $soapServerBuilder = new SoapServerBuilder(); $soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService); $soapOptions = SoapOptionsBuilder::createWithClassMap($dummyService->getWsdlPath(), $classMap); $soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions); $request = $soapServer->createRequest( $dummyService->getEndpoint(), 'DummyService.dummyServiceMethod', 'text/xml;charset=UTF-8', '<received><soap><request><here /></request></soap></received>' ); $response = $soapServer->handleRequest($request); var_dump($response); // Contains Response, Attachments
In this example, a DummyService service has been used to handle request.
Using a service can help you create coherent SoapServer endpoints.
Service can hold an endpoint URL, WSDL path and a class map as associative array.
You can hold a class map as ClassMap object directly in the DummyService instead of array.
In the service you should describe SOAP methods from given WSDL. In the example, the dummyServiceMethod is called. The method will receive request object and return response object that are matched according to the class map.
See a simplified implementation of dummyServiceMethod to get a clue:
/**
* @param DummyServiceRequest $dummyServiceRequest
* @return DummyServiceResponse
*/
public function dummyServiceMethod(DummyServiceRequest $dummyServiceRequest)
{
$response = new DummyServiceResponse();
$response->status = true;
return $response;
}
For further information and getting inspiration for your implementation, see the unit tests in tests dir.
Contribute
Feel free to contribute! Please, run the tests via Phing php phing -f build.xml.
Warning: Unit tests may fail under Windows OS, tested under Linux, MacOS.
tuscanicz/soap 适用场景与选型建议
tuscanicz/soap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.02k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2016 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「soap」 「soap server」 「soap client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tuscanicz/soap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tuscanicz/soap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tuscanicz/soap 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
A PHP client for the Salesforce SOAP API
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A Yii2 component for working with TurboSMS.ua SOAP service
Zend Framework 1 Soap package
Mock PSR-18 HTTP client
统计信息
- 总下载量: 39.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-27