File tree 2 files changed +22
-3
lines changed 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,8 @@ public function validateExistence($vatNumber) {
99
99
* @param string $vatNumber Either the full VAT number (incl. country) or just the part after the country code.
100
100
*
101
101
* @return boolean
102
+ *
103
+ * @throws Vies\ViesException
102
104
*/
103
105
public function validate ( $ vatNumber ) {
104
106
return $ this ->validateFormat ( $ vatNumber ) && $ this ->validateExistence ( $ vatNumber );
Original file line number Diff line number Diff line change @@ -15,15 +15,20 @@ class Client {
15
15
/**
16
16
* @var SoapClient
17
17
*/
18
- protected $ client ;
18
+ private $ client ;
19
+
20
+ /**
21
+ * @var int
22
+ */
23
+ protected $ timeout ;
19
24
20
25
/**
21
26
* Client constructor.
22
27
*
23
28
* @param int $timeout How long should we wait before aborting the request to VIES?
24
29
*/
25
30
public function __construct ($ timeout = 10 ) {
26
- $ this ->client = new SoapClient ( self :: URL , [ ' connection_timeout ' => $ timeout ]) ;
31
+ $ this ->timeout = $ timeout ;
27
32
}
28
33
29
34
/**
@@ -36,7 +41,7 @@ public function __construct($timeout = 10) {
36
41
*/
37
42
public function checkVat ( $ countryCode , $ vatNumber ) {
38
43
try {
39
- $ response = $ this ->client ->checkVat (
44
+ $ response = $ this ->getClient () ->checkVat (
40
45
array (
41
46
'countryCode ' => $ countryCode ,
42
47
'vatNumber ' => $ vatNumber
@@ -48,4 +53,16 @@ public function checkVat( $countryCode, $vatNumber ) {
48
53
49
54
return (bool ) $ response ->valid ;
50
55
}
56
+
57
+ /**
58
+ * @return SoapClient
59
+ */
60
+ protected function getClient ()
61
+ {
62
+ if ($ this ->client === null ) {
63
+ $ this ->client = new SoapClient (self ::URL , ['connection_timeout ' => $ this ->timeout ]);
64
+ }
65
+
66
+ return $ this ->client ;
67
+ }
51
68
}
You can’t perform that action at this time.
0 commit comments