Installation
composer require besimple/soap-bundle
Enable the bundle in config/bundles.php:
return [
// ...
BeSimple\SoapBundle\BeSimpleSoapBundle::class => ['all' => true],
];
First Use Case: Consuming a SOAP Service
Define a client in config/packages/besimple_soap.yaml:
besimple_soap:
clients:
example:
wsdl: "http://example.com/service?wsdl"
options:
trace: true
exceptions: true
Use the client in a service/controller:
use BeSimple\SoapBundle\Client\SoapClient;
public function callService(SoapClient $client)
{
$result = $client->call('ServiceMethod', ['param1' => 'value']);
return $result;
}
First Use Case: Exposing a SOAP Service
Define a server in config/packages/besimple_soap.yaml:
besimple_soap:
servers:
example:
uri: "/soap"
class: "AppBundle\Service\SoapService"
options:
classmap: ["AppBundle\\"]
Implement a service class:
namespace AppBundle\Service;
class SoapService
{
public function someMethod($param1) {
return "Processed: " . $param1;
}
}
Dependency Injection
Inject SoapClient into controllers/services:
public function __construct(SoapClient $client) {
$this->client = $client;
}
Dynamic WSDL Loading Load WSDL dynamically in runtime:
$client = $this->get('besimple_soap.client.example');
$client->setWsdl('http://new-service.com?wsdl');
Error Handling
Use exceptions: true in config to throw SOAP faults as exceptions:
try {
$result = $client->call('FaultyMethod');
} catch (\SoapFault $fault) {
// Handle error
}
Logging
Enable trace: true for debugging:
options:
trace: true
Class Mapping
Use classmap to auto-discover methods:
options:
classmap: ["AppBundle\\"]
Custom Logic
Implement BeSimple\SoapBundle\Server\ServerInterface for advanced use cases.
Security
Secure endpoints with Symfony’s security system (e.g., @IsGranted annotations).
Performance Cache WSDL responses if static:
options:
cache_wsdl: true
WSDL Caching
cache_wsdl if WSDL changes frequently.php bin/console cache:clear
Namespace Conflicts
new, return).Large Payloads
soap.wsdl_cache and soap.wsdl_cache_dir limits in php.ini if handling large WSDLs.Debugging
trace: true and check Symfony logs for raw SOAP requests/responses:
php bin/console debug:container | grep besimple_soap
Type Hints Use PHP 7.4+ return type hints for SOAP responses:
public function getUserData(): array {
return $this->client->call('GetUser', ['id' => 1]);
}
Testing
Mock SoapClient in PHPUnit:
$mock = $this->createMock(SoapClient::class);
$mock->method('call')->willReturn(['data' => 'test']);
$this->container->set('besimple_soap.client.example', $mock);
Documentation
Generate WSDL docs with besimple_soap.wsdl_generator:
besimple_soap:
wsdl_generator:
enabled: true
output_dir: "%kernel.project_dir%/var/cache/wsdl"
Extensions
Extend BeSimple\SoapBundle\Client\SoapClient for custom logic (e.g., headers, namespaces):
class CustomSoapClient extends SoapClient {
public function addHeader($header) {
$this->__setSoapHeaders([new SoapHeader(null, $header)]);
}
}
Symfony 5+ Compatibility
autoconfigure: false in bundles.php if encountering autowiring issues:
BeSimple\SoapBundle\BeSimpleSoapBundle::class => ['all' => true, 'autoconfigure' => false],
How can I help you explore Laravel packages today?