splash/soap
Technical SOAP bundle for testing generic connector interfaces. Intended for internal/QA use rather than production, providing a minimal harness to validate connector behavior and interoperability in Splash-based integrations.
Installation Add the package via Composer:
composer require splash/soap
Register the bundle in config/app.php under providers:
BadPixxel\SoapBundle\SoapBundle::class,
Basic Configuration
Publish the default config (if available) and update config/soap.php:
php artisan vendor:publish --provider="BadPixxel\SoapBundle\SoapBundle" --tag="config"
Configure your SOAP endpoint, WSDL, and client options:
'clients' => [
'default' => [
'wsdl' => 'http://example.com/service?wsdl',
'options' => [
'trace' => 1,
'exceptions' => true,
],
],
],
First SOAP Call
Inject the SoapClient via Laravel’s service container:
use BadPixxel\SoapBundle\Service\SoapService;
public function __construct(private SoapService $soapService) {}
public function callSoapService()
{
$client = $this->soapService->getClient('default');
$response = $client->someMethod(['param1' => 'value1']);
return $response;
}
Service Layer Abstraction Create a dedicated service class to encapsulate SOAP logic:
namespace App\Services;
use BadPixxel\SoapBundle\Service\SoapService;
class ExternalApiService {
public function __construct(private SoapService $soapService) {}
public function fetchUserData(int $userId): array
{
$client = $this->soapService->getClient('user_service');
return $client->getUserById(['id' => $userId]);
}
}
Error Handling Centralize SOAP error handling in a middleware or decorator:
try {
$response = $this->soapService->call('default', 'method', [$param]);
} catch (\SoapFault $fault) {
Log::error("SOAP Error: {$fault->getMessage()}");
throw new \RuntimeException("External API failed", 500);
}
Dynamic Client Configuration Override client settings per request (e.g., for testing):
$client = $this->soapService->getClient('default', [
'options' => ['trace' => 1, 'exceptions' => false],
]);
Caching Responses Cache SOAP responses to reduce latency (e.g., using Laravel’s cache):
$cacheKey = "soap_user_{$userId}";
return Cache::remember($cacheKey, now()->addHours(1), function () use ($userId) {
return $this->fetchUserData($userId);
});
WSDL Caching Issues
SoapClient caches WSDLs aggressively, causing stale schemas.'options' => ['cache_wsdl' => WSDL_CACHE_NONE],
Or use SoapClient::resetCache().Namespace Collisions
stdClass with conflicting properties).$data = (array) $response->someMethod();
Timeouts and Large Payloads
connection_timeout and local_cert in client options:
'options' => [
'connection_timeout' => 30,
'stream_context' => stream_context_create([
'ssl' => ['verify_peer' => false], // For testing only!
]),
],
Laravel Service Container Conflicts
SoapClient instances properly, leading to singleton issues.$this->app->bind('soap.client.default', function ($app) {
return new \SoapClient(
$app['config']['soap.clients.default.wsdl'],
$app['config']['soap.clients.default.options']
);
});
Logging SOAP Requests/Responses
Enable trace in options and log raw data:
'options' => ['trace' => 1],
Access traces via:
$request = $client->__getLastRequest();
$response = $client->__getLastResponse();
Testing SOAP Services
Use mocks in PHPUnit to stub SOAP calls:
$mock = $this->getMockBuilder(\SoapClient::class)
->disableOriginalConstructor()
->onlyMethods(['someMethod'])
->getMock();
$mock->method('someMethod')->willReturn(['mocked' => 'data']);
Extending the Bundle
SoapService to add custom logic (e.g., retry logic, headers):
namespace App\Services;
use BadPixxel\SoapBundle\Service\SoapService as BaseSoapService;
class CustomSoapService extends BaseSoapService {
public function call($clientName, $method, $params, $retries = 3) {
// Custom retry logic here
return parent::call($clientName, $method, $params);
}
}
AppServiceProvider:
$this->app->bind(\BadPixxel\SoapBundle\Service\SoapService::class, App\Services\CustomSoapService::class);
Security Considerations
exceptions => false in production (use middleware to handle faults).How can I help you explore Laravel packages today?