sourcetoad/soapy
Composer 安装命令:
composer require sourcetoad/soapy
包简介
A Soap Client built for Laravel.
README 文档
README
SOAP is old, but still used. Soapy is modern, but feature limited to fit our use cases.
Heavily inspired by artisaninweb/laravel-soap.
Install
This package is currently supporting Laravel 11.x and 12.x.
composer require sourcetoad/soapy
This package will use Laravel Auto Discovery to automatically register the Service Provider.
Documentation
Options
- wsdl - Location to flat file or URL for WSDL.
- trace - Whether to expose internal methods on SoapClient.
- cache - Flag to use for WSDL cache.
- location - Override URL to use for SOAP Requests.
- uri - Override namespace to use for SOAP Requests.
- certificate - Certificate path for authentication with Server.
- options - Array of any settings from SoapClient#options
- classmap - Array of class maps to map objects -> classes.
- typemap - Array of type maps. (Documentation WIP)
Example (Class maps)
Creating a client and making a request with class maps.
$this->client = SoapyFacade::create(function (SoapyCurtain $curtain) { return $curtain ->setWsdl('https://example.org?wsdl') ->setTrace(true) ->setOptions([ 'encoding' => 'UTF-8' ]) ->setClassMap([ 'Foo' => Foo::class, 'FooResponse' => FooResponse::class ]) ->setCache(WSDL_CACHE_MEMORY) ->setLocation('https://example.org'); });
Presuming you had XML for the expected request like this.
<Foo> <bar>Connor</bar> <baz>true</baz> </Foo>
You could produce a matching class to resemble that data.
<?php class Foo { protected $bar; protected $baz; public function __construct(string $bar, bool $baz) { $this->bar = $bar; $this->baz = $baz; } }
You could then call a fictitious method name "fizz" on the SOAP Class like.
$this->client->call('fizz', new Foo("Connor", true));
This shows the benefit of never messing with XML directly.
Likewise for the response. Imagine you got back this.
<FooResponse> <status>Success.</status> </FooResponse>
This can also be mapped with the following class.
<?php class FooResponse { protected $status; }
So now you can do:
echo $this->client->call('fizz', new Foo("Connor", true))->status; // Success.
Example (No Class maps)
This example shows bare minimum WSDL location and no class maps.
$this->client = SoapyFacade::create(function (SoapyCurtain $curtain) { return $curtain ->setWsdl('https://example.org?wsdl') });
Presuming you had XML for the expected request like this.
<Foo> <bar>Connor</bar> <baz>true</baz> </Foo>
You could then call a fictitious method name "fizz" on the SOAP Class like.
$this->client->call('fizz', [ 'bar' => 'Connor', 'baz' => true });
This is more error prone due to human error with keys, but less work.
Example (Custom Client)
Sometimes you may have a SOAP Integration that just isn't fun. It may use something that our default SoapyClient cannot handle. This is okay, because patching a generic SOAP Client for all the strangeness that can happen is not feasible.
Start with a new class, that extends our SoapyBaseClient.
<?php class CustomClass extends \Sourcetoad\Soapy\SoapyBaseClient { // }
From that class. You can overload any of the functions it provides.
Then pass the class name (fully qualified) to the Curtain during generation.
$this->client = SoapyFacade::create(function (SoapyCurtain $curtain) { return $curtain ->setWsdl('https://example.org?wsdl') }, CustomClass::class);
sourcetoad/soapy 适用场景与选型建议
sourcetoad/soapy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99.45k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2019 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「client」 「soap」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sourcetoad/soapy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sourcetoad/soapy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sourcetoad/soapy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
A PHP client for the Salesforce SOAP API
A Yii2 component for working with TurboSMS.ua SOAP service
Zend Framework 1 Soap package
Mock PSR-18 HTTP client
NuSOAP PHP library re-packaged for Packagist/Composer
统计信息
- 总下载量: 99.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 5
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-26