4
4
5
5
use GuzzleHttp \Client ;
6
6
use GuzzleHttp \Psr7 \HttpFactory ;
7
+ use h4kuna \Dir \Dir ;
7
8
use h4kuna \Dir \TempDir ;
8
9
use h4kuna \Fio ;
9
- use h4kuna \Fio \Account ;
10
10
use Psr \Http \Client \ClientInterface ;
11
11
12
12
class FioFactory
@@ -15,20 +15,23 @@ class FioFactory
15
15
16
16
protected Utils \Queue $ queue ;
17
17
18
- protected TempDir $ tempDir ;
19
-
20
18
21
19
/**
22
20
* @param array<array{token: string, account: string}> $accounts
23
21
*/
24
22
public function __construct (
25
23
array $ accounts ,
26
- string $ temp = 'fio ' ,
27
- )
28
- {
29
- $ this ->tempDir = new TempDir ($ temp );
24
+ string |Dir $ temp = 'fio ' ,
25
+ ?ClientInterface $ client = null ,
26
+ ?Utils \FioRequestFactory $ fioRequestFactory = null ,
27
+ ) {
28
+
30
29
$ this ->accountCollection = $ this ->createAccountCollection ($ accounts );
31
- $ this ->queue = $ this ->createQueue ();
30
+ $ this ->queue = $ this ->createQueue (
31
+ is_string ($ temp ) ? new TempDir ($ temp ) : $ temp ,
32
+ $ client ?? self ::createClientInterface (),
33
+ $ fioRequestFactory ?? self ::createRequestFactory ()
34
+ );
32
35
}
33
36
34
37
@@ -44,9 +47,9 @@ public function createFioPay(string $name = ''): Fio\FioPay
44
47
}
45
48
46
49
47
- protected function createQueue (): Utils \Queue
50
+ protected function createQueue (Dir $ tempDir , ClientInterface $ client , Utils \ FioRequestFactory $ fioRequestFactory ): Utils \Queue
48
51
{
49
- return new Utils \Queue ($ this -> tempDir , $ this -> createClientInterface () , $ this -> createRequestFactory () );
52
+ return new Utils \Queue ($ tempDir , $ client , $ fioRequestFactory );
50
53
}
51
54
52
55
@@ -75,15 +78,15 @@ protected function createXmlFile(): Pay\XMLFile
75
78
}
76
79
77
80
78
- private function createClientInterface (): ClientInterface
81
+ private static function createClientInterface (): ClientInterface
79
82
{
80
83
Fio \Exceptions \MissingDependency::checkGuzzlehttp ();
81
84
82
85
return new Client ();
83
86
}
84
87
85
88
86
- private function createRequestFactory (): Utils \FioRequestFactory
89
+ private static function createRequestFactory (): Utils \FioRequestFactory
87
90
{
88
91
Fio \Exceptions \MissingDependency::checkGuzzlehttp ();
89
92
0 commit comments