katalystsol / php-soap-client
A generic PHP SOAP Client
Requires
- php: ~5.6|~7.0
- ext-json: *
- ext-simplexml: *
- ext-soap: *
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2025-04-14 21:10:07 UTC
README
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.
Goals
- 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.
Install
Via Composer
$ composer require katalystsol/php-soap-client
Requirements
The 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
Documentation
Constructive feedback is always welcome...
Example Usage
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);
Example SOAP Method class
use Katalystsol\PhpSoapClient\ConsumerMethod; class GetBookingPolicies extends ConsumerMethod { protected $requiredParameters = [ 'strUserId', 'strPassword', 'strCOID', ]; protected $optionalParameters = [ 'strProperty', ]; }
Example Complex Type
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.
License
The MIT License (MIT). Please see License File for more information.