Installation:
composer require besimple/soap-wsdl:0.2.*@dev
Verify the package loads by checking vendor/composer/autoload_psr4.php for BeSimple\SoapWsdl.
First Use Case: Consuming a SOAP Service
use BeSimple\SoapWsdl\Client;
$client = new Client('http://example.com/soap-service?wsdl');
$response = $client->__soapCall('MethodName', ['param1' => 'value1']);
Where to Look First:
Client class).src/Client.php for core methods like __soapCall(), setOptions(), and getFunctions().tests/ for real-world integration patterns (if available).Service Consumption:
$client = new Client('http://example.com/wsdl');
$result = $client->__soapCall('GetUserData', ['userId' => 123]);
getFunctions() to fetch available methods and validate inputs:
$methods = $client->getFunctions();
if (in_array('GetUserData', $methods)) {
$client->__soapCall('GetUserData', ['userId' => 123]);
}
Request Customization:
$client->setOptions([
'trace' => 1,
'exceptions' => true,
'soap_version' => SOAP_1_2,
'login' => 'user',
'password' => 'pass',
]);
$client = new Client('file:///path/to/local/wsdl.xml');
Laravel Integration:
// app/Providers/SoapServiceProvider.php
public function register()
{
$this->app->singleton('soap.client', function () {
return new Client(config('soap.wsdl_url'));
});
}
config/soap.php):
return [
'wsdl_url' => env('SOAP_WSDL_URL', 'http://default.com/wsdl'),
'default_options' => [
'trace' => true,
],
];
// app/Facades/Soap.php
public static function call($method, $params = [])
{
return app('soap.client')->__soapCall($method, $params);
}
Error Handling:
try {
$client->__soapCall('FaultyMethod', []);
} catch (SoapFault $fault) {
Log::error("SOAP Error: {$fault->getMessage()}");
throw new \RuntimeException('Service unavailable', 503);
}
WSDL Parsing Issues:
getFunctions() to validate the WSDL is parsed correctly before calling methods.trace in options to inspect raw SOAP requests/responses:
$client->setOptions(['trace' => 1]);
$response = $client->__soapCall(...);
var_dump($client->__getLastRequest(), $client->__getLastResponse());
Namespace Conflicts:
SoapClient if autoloading isn’t isolated.use BeSimple\SoapWsdl\Client as SoapWsdlClient;
Version Locking:
0.2.*@dev state; updates may break compatibility.composer.json:
"besimple/soap-wsdl": "0.2.0"
Laravel Caching Quirks:
php artisan cache:clear
php artisan view:clear
Performance:
Client once (e.g., as a singleton) to avoid WSDL re-parsing:
$client = new Client('http://example.com/wsdl');
// Reuse $client for multiple calls
Testing:
Mockery to stub SoapClient:
$mock = Mockery::mock('overload:BeSimple\SoapWsdl\Client');
$mock->shouldReceive('__soapCall')->andReturn(['data' => 'test']);
Extension Points:
$client->setOptions([
'headers' => [
new SoapHeader('http://namespace', 'AuthHeader', ['token' => 'abc123']),
],
]);
Client to add pre/post-processing:
class CustomClient extends Client {
public function __soapCall($method, $params) {
$this->logRequest($method, $params);
return parent::__soapCall($method, $params);
}
}
Logging:
$client->setOptions(['trace' => 1]);
$client->__soapCall('Method', []);
Log::info('SOAP Request:', [
'request' => $client->__getLastRequest(),
'response' => $client->__getLastResponse(),
]);
Fallback to Native SoapClient:
$nativeClient = new \SoapClient('http://example.com/wsdl');
$nativeClient->__setLocation('http://override.com/endpoint');
How can I help you explore Laravel packages today?