composer require capdigital/ntlmsoapclient
/config/bundles.php:
Capdigital\NtlmSoapClient\CapdigitalNTLMSoapClient::class => ['all' => true]
/config/packages/capdigital_ntlm_soap_client.yaml):
capdigital_ntlm_soap_client:
url: "http://your-soap-server"
port: "8080"
server: "DOMAIN_SERVER"
society: "COMPANY_NAME"
user: "DOMAIN\\USERNAME"
password: "PASSWORD"
use Capdigital\NtlmSoapClient\Service\CapdigitalNtlmSoapClient;
class MyController extends Controller
{
public function index(CapdigitalNtlmSoapClient $ntlmClient)
{
$client = $ntlmClient->connect('SystemService');
$result = $client->Companies();
return response()->json($result->return_value);
}
}
public function __construct(private CapdigitalNtlmSoapClient $ntlmClient) {}
public function fetchData()
{
$client = $this->ntlmClient->connect('SystemService');
// Use $client...
}
Reusable Connection Handling: Create a wrapper class for common SOAP calls:
class CompanyService
{
public function __construct(private CapdigitalNtlmSoapClient $ntlmClient) {}
public function getCompanies(): array
{
$client = $this->ntlmClient->connect('SystemService');
return $client->Companies()->return_value;
}
}
Error Handling: Wrap SOAP calls in try-catch blocks:
try {
$result = $client->SomeMethod();
} catch (SoapFault $e) {
Log::error("SOAP Error: " . $e->getMessage());
throw new \RuntimeException("SOAP service unavailable");
}
Dynamic Configuration:
Override config per environment (e.g., .env):
# config/packages/capdigital_ntlm_soap_client.yaml
capdigital_ntlm_soap_client:
url: "%env(SOAP_URL)%"
$this->app->bind(CapdigitalNtlmSoapClient::class, function ($app) {
return new CapdigitalNtlmSoapClient(
$app['config']['capdigital_ntlm_soap_client']
);
});
$client->setDebug(true); // If supported (check package docs)
NTLM Authentication:
SoapUI first.DOMAIN\user vs user@domain).Connection Pooling:
$client = $ntlmClient->connect('ServiceName');
// Use $client...
$client->__soapCall('__soapClose'); // Hypothetical; verify API
Deprecated Methods:
Configuration Overrides:
connect() method for defaults.$client = $ntlmClient->connect('ServiceName');
$client->setUseCurl(true); // If supported
ini_set('soap.wsdl_cache_enabled', 0); // Disable caching for testing
Environment-Specific Config:
Use Laravel’s config() helper to merge defaults:
$config = array_merge([
'url' => env('SOAP_URL'),
'port' => env('SOAP_PORT', 80),
], config('capdigital_ntlm_soap_client'));
Testing: Mock the SOAP client for unit tests:
$mockClient = $this->createMock(\SoapClient::class);
$mockClient->method('Companies')->willReturn((object)['return_value' => []]);
$this->app->instance(CapdigitalNtlmSoapClient::class, new class($mockClient) {
public function connect($wsName) { return $this->client; }
});
Fallback for Failures: Implement a retry mechanism for transient failures:
use Symfony\Component\Process\Exception\ProcessFailedException;
try {
$result = $client->SomeMethod();
} catch (SoapFault $e) {
if (str_contains($e->getMessage(), 'timeout')) {
sleep(2);
return $this->fetchData(); // Recursive retry
}
throw $e;
}
Security:
env() or a secrets manager.Extending the Package:
connect() method to add custom logic:
class CustomNtlmSoapClient extends CapdigitalNtlmSoapClient
{
public function connect($wsName, $deleteSociety = false)
{
$client = parent::connect($wsName, $deleteSociety);
$client->setUseCurl(true); // Example extension
return $client;
}
}
How can I help you explore Laravel packages today?