borkness / lather
易于使用的 SOAP 客户端
dev-master
2020-10-13 15:25 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^3.9
This package is not auto-updated.
Last update: 2024-09-26 08:42:17 UTC
README
Lather 是一个简单易用的 PHP 7.2+ SOAP 客户端。
通过使用 Lather,查询 SOAP API 变得非常简单。
注意: Lather 仍在开发中,因此方法可能会发生变化
安装
Lather 需要安装 ext-soap 扩展,并且你的 PHP 版本必须是 7.2 或更高。
Composer
composer require borkness\lather
基本用法
首先,你必须创建一个类,默认情况下,将被调用的 soap 函数名称将是类的名称,定义将与 WSDL 一起调用的参数。
<?php namespace App; use Lather\Lather; class Add extends Lather { protected $parameters = [ 'number1', 'number2', ]; protected $wsdl = 'calculator.wsdl'; }
现在,你已准备好调用 SOAP 服务。
<?php require_once('vendor/autoload.php'); $add = new App\Add(); $add->call(['number1' => 5, 'number2' => 5]); print_r($add->all());
响应
Array
(
[AddResult] => 10
)
连接
您可以使用 Lather 中的连接功能来获取多个 SOAP 操作返回的单个响应数组中的数据。
使用键作为类名和值作为响应的数组指定 $joins
,ID 格式为逗号分隔的字符串。
示例
<?php namespace App; use Lather\Lather; class GetCountryISOCode extends Lather { protected $wsdl = 'CountryInfoService.wsdl'; protected $params = [ 'sCountryName' => 'string', ]; protected $functionName = 'CountryISOCode'; /* Joins: Format of Class name as key with ResultArray and Join Id as comma value */ protected $joins = [ CapitalCity::class => 'CountryISOCodeResult,sCountryISOCode', CountryCurrency::class => 'CountryISOCodeResult,sCountryISOCode', ]; }
<?php require_once('vendor/autoload.php'); $countryCode = new App\GetCountryISOCode(); $countryCode->sCountryName = 'Denmark'; $countryCode->call(); print_r($countryCode->all());
响应
Array
(
[CountryISOCodeResult] => DK
[CapitalCityResult] => Copenhagen
[CountryCurrencyResult] => Array
(
[sISOCode] => DKK
[sName] => Kroner
)
)