Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from spaze/spaze/soapclient-timeout
Browse files Browse the repository at this point in the history
`SoapClient` timeout
  • Loading branch information
spaze authored Jul 26, 2022
2 parents abcc1a5 + 0c4973f commit 727295a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/VatCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class VatCalculator
/** @var string */
private $businessVatNumber;

/** @var float */
private $timeout;

public function __construct(VatRates $vatRates, ?string $businessCountryCode = null, ?string $businessVatNumber = null)

public function __construct(VatRates $vatRates, ?string $businessCountryCode = null, ?string $businessVatNumber = null, ?float $timeout = null)
{
$this->vatRates = $vatRates;
if ($businessCountryCode) {
Expand All @@ -43,6 +46,7 @@ public function __construct(VatRates $vatRates, ?string $businessCountryCode = n
if ($businessVatNumber) {
$this->setBusinessVatNumber($businessVatNumber);
}
$this->timeout = $timeout ?? (float)ini_get('default_socket_timeout');
}


Expand Down Expand Up @@ -172,7 +176,16 @@ public function getVatDetails(string $vatNumber, ?string $requesterVatNumber = n

try {
if ($this->soapClient === null) {
$this->soapClient = new SoapClient(self::VAT_SERVICE_URL);
$this->soapClient = new SoapClient(
self::VAT_SERVICE_URL,
[
'stream_context' => stream_context_create([
'http' => [
'timeout' => $this->timeout,
],
]),
],
);
}
if ($requesterVatNumber === null) {
$requesterVatNumber = $this->businessVatNumber;
Expand Down

0 comments on commit 727295a

Please sign in to comment.