diff --git a/src/FioFactory.php b/src/FioFactory.php index d898c83..463adfe 100644 --- a/src/FioFactory.php +++ b/src/FioFactory.php @@ -4,9 +4,9 @@ use GuzzleHttp\Client; use GuzzleHttp\Psr7\HttpFactory; +use h4kuna\Dir\Dir; use h4kuna\Dir\TempDir; use h4kuna\Fio; -use h4kuna\Fio\Account; use Psr\Http\Client\ClientInterface; class FioFactory @@ -15,20 +15,23 @@ class FioFactory protected Utils\Queue $queue; - protected TempDir $tempDir; - /** * @param array $accounts */ public function __construct( array $accounts, - string $temp = 'fio', - ) - { - $this->tempDir = new TempDir($temp); + string|Dir $temp = 'fio', + ?ClientInterface $client = null, + ?Utils\FioRequestFactory $fioRequestFactory = null, + ) { + $this->accountCollection = $this->createAccountCollection($accounts); - $this->queue = $this->createQueue(); + $this->queue = $this->createQueue( + is_string($temp) ? new TempDir($temp) : $temp, + $client ?? self::createClientInterface(), + $fioRequestFactory ?? self::createRequestFactory() + ); } @@ -44,9 +47,9 @@ public function createFioPay(string $name = ''): Fio\FioPay } - protected function createQueue(): Utils\Queue + protected function createQueue(Dir $tempDir, ClientInterface $client, Utils\FioRequestFactory $fioRequestFactory): Utils\Queue { - return new Utils\Queue($this->tempDir, $this->createClientInterface(), $this->createRequestFactory()); + return new Utils\Queue($tempDir, $client, $fioRequestFactory); } @@ -75,7 +78,7 @@ protected function createXmlFile(): Pay\XMLFile } - private function createClientInterface(): ClientInterface + private static function createClientInterface(): ClientInterface { Fio\Exceptions\MissingDependency::checkGuzzlehttp(); @@ -83,7 +86,7 @@ private function createClientInterface(): ClientInterface } - private function createRequestFactory(): Utils\FioRequestFactory + private static function createRequestFactory(): Utils\FioRequestFactory { Fio\Exceptions\MissingDependency::checkGuzzlehttp(); diff --git a/src/Utils/Queue.php b/src/Utils/Queue.php index 132c8b6..26f56b9 100644 --- a/src/Utils/Queue.php +++ b/src/Utils/Queue.php @@ -2,7 +2,7 @@ namespace h4kuna\Fio\Utils; -use h4kuna\Dir\TempDir; +use h4kuna\Dir\Dir; use h4kuna\Fio\Exceptions; use h4kuna\Fio\Pay\Response; use h4kuna\Fio\Pay\XMLResponse; @@ -26,11 +26,10 @@ class Queue public function __construct( - private TempDir $tempDir, + private Dir $tempDir, private ClientInterface $client, private FioRequestFactory $requestFactory, - ) - { + ) { } diff --git a/tests/src/Fixtures/FioFactory.php b/tests/src/Fixtures/FioFactory.php index 8f7451d..fd3aa97 100644 --- a/tests/src/Fixtures/FioFactory.php +++ b/tests/src/Fixtures/FioFactory.php @@ -2,8 +2,11 @@ namespace h4kuna\Fio\Tests\Fixtures; +use h4kuna\Dir\Dir; use h4kuna\Fio\Pay\XMLFile; use h4kuna\Fio\Read\Json; +use h4kuna\Fio\Utils\FioRequestFactory; +use Psr\Http\Client\ClientInterface; class FioFactory extends \h4kuna\Fio\FioFactory { @@ -36,7 +39,7 @@ public function getReader(): Json } - protected function createQueue(): Queue + protected function createQueue(Dir $tempDir, ClientInterface $client, FioRequestFactory $fioRequestFactory): Queue { return new Queue(); }