Installation:
composer require besimple/soap-common:0.2.*@dev
Verify the package loads in config/app.php under providers.
First Use Case:
SoapClient wrapper to handle MIME attachments (SwA/MTOM):
use BeSimple\SoapCommon\SoapClient\SoapClient;
use BeSimple\SoapCommon\SoapClient\SoapClientOptions;
$options = new SoapClientOptions();
$options->setWsdl('path/to/wsdl.wsdl');
$options->setClassMap([...]); // Map complex types if needed
$client = new SoapClient($options);
$response = $client->__soapCall('methodName', [$arg1, $arg2]);
BeSimple\SoapCommon\SoapServer\SoapServer to define endpoints:
use BeSimple\SoapCommon\SoapServer\SoapServer;
$server = new SoapServer('path/to/wsdl.wsdl', [
'classmap' => [...],
'uri' => 'http://example.com/soap'
]);
$server->handle();
Key Files:
src/SoapClient/ and src/SoapServer/ for core logic.src/TypeConverter/ for custom type handling.Client-Side Workflow:
SoapClientOptions to configure:
$options->setMimeType('multipart/related'); // For SwA/MTOM
$options->setAttachments([...]); // Binary data (e.g., files)
$response->getMimeParts() or raw XML with $response->getRawResponse().Server-Side Workflow:
SoapServer methods or use annotations (if supported) to map PHP methods to SOAP actions.$attachments = $request->getMimeParts();
foreach ($attachments as $attachment) {
$data = $attachment->getData();
}
Type Conversion:
SoapClientOptions:
$options->addTypeConverter(new CustomTypeConverter());
classmap:
$options->setClassMap([
'ns\ComplexType' => 'App\Models\ComplexTypeModel'
]);
SoapClient to the container in AppServiceProvider:
$this->app->bind(SoapClient::class, function ($app) {
return new SoapClient(new SoapClientOptions());
});
SoapClient/SoapServer in unit tests:
$mockClient = Mockery::mock(SoapClient::class);
$mockClient->shouldReceive('__soapCall')->andReturn($mockResponse);
MIME Handling:
upload_max_filesize or post_max_size. Adjust in php.ini or stream attachments directly to storage.Type Conversion:
classmap will cause silent failures. Validate mappings with:
$options->validateClassMap();
WSDL Caching:
$options->setCacheWsdl(false)) to avoid stale schemas.$options->setDebug(true); // Logs requests/responses to storage/logs/soap.log
file_put_contents('debug.xml', $response->getRawResponse());
SOAP-ENV:Client: Validate WSDL URL and namespace URIs.SOAP-ENV:Server: Check for missing method annotations or unregistered classmaps.Custom MIME Parsers:
Extend BeSimple\SoapCommon\Mime\MimeParser to support non-standard MIME formats.
Security:
$server->setAllowedActions(['ns:safeAction']);
Performance:
SoapResponseStream to avoid memory overload.SoapClient::setBatchMode(true) for bulk operations.targetNamespace in WSDL or adjust classmap keys.$options->setDebug(false)) to avoid log exposure.How can I help you explore Laravel packages today?