A generic SOAP client
This was originally written as a SOAP Client in Laravel to access the HomeAway SOAP API. This is a work-in-progress to migrate that code to be a simple-to-use, generic SOAP client.
- Create a simple approach to interacting with a SOAP API
- Create a Class for each API endpoint method that only requires minimal data parameters for required and optional parameters.
- Have ability to support complex types / objects.
- Adhere as closely as possible to the Single Responsibility principle.
- Each SOAP API endpoint/method will be its own Class, which configures the required parameters, optional parameters and/or complex types. It should only change if the SOAP API changes.
This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Via Composer
$ composer require katalystsol/php-soap-clientThe following versions of PHP are supported by this version.
- PHP 5.6
- PHP 7.0
- PHP 7.1
- PHP 7.2
- PHP 7.3
It requires the following PHP extensions:
- JSON
- SimpleXML
- SOAP
Constructive feedback is always welcome...
To use the class, you would:
- Instantiate the client
- Set up the parameters to pass to the method
- Call the method to return the response
$wdsl = 'https://secure.instantsoftwareonline.com/StayUSA/ChannelPartners/wsWeblinkPlusAPI.asmx?WSDL';
$soapClientOptions = [
'trace' => true,
];
$client = new SoapClientLogger(new \SoapClient($wdsl, $soapClientOptions));
$params = [
'strUserId' => 'testUserId',
'strPassword' => 'testPassword',
'strCOID' => '1234',
];
$response = (new Consumer($client))->getBookingPolicies($params);use Katalystsol\PhpSoapClient\ConsumerMethod;
class GetBookingPolicies extends ConsumerMethod
{
protected $requiredParameters = [
'strUserId',
'strPassword',
'strCOID',
];
protected $optionalParameters = [
'strProperty',
];
}This would be a credit card class. It would also reference a separate complex type class "ClsAddress".
use Katalystsol\PhpSoapClient\ComplexType;
class ClsCreditCard extends ComplexType
{
protected function setPropertyKeys()
{
$this->propertyKeys = [
'strToken',
'strCCType',
'intExpMonth',
'intExpYear',
'strName',
'objBillingAddress',
'strEmail',
];
}
protected function setComplexTypes()
{
$this->complexTypes = [
'objBillingAddress' => ClsAddress::class,
];
}
protected function setComplexTypeClassName()
{
$this->complexTypeClassName = get_class();
}
}- See the tests for more examples.
The MIT License (MIT). Please see License File for more information.