Skip to content

Commit

Permalink
feat(ExchangeFactory): add more option
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Aug 29, 2024
1 parent 31117aa commit 64c4dcd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/ExchangeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Psr7\HttpFactory;
use h4kuna\CriticalCache\PSR16\CacheLockingFactoryInterface;
use h4kuna\CriticalCache\PSR16\Locking\CacheLockingFactory;
use h4kuna\Dir\Dir;
use h4kuna\Exchange\Download\SourceDownload;
use h4kuna\Exchange\Exceptions\MissingDependencyException;
use h4kuna\Exchange\RatingList\CacheEntity;
Expand All @@ -31,10 +32,11 @@ public function __construct(
?ClientInterface $client = null,
?RequestFactoryInterface $requestFactory = null,
?CacheEntity $cacheEntity = null,
string|Dir|CacheLockingFactoryInterface $tempDir = 'exchange',
)
{
$this->cacheEntity = $cacheEntity ?? new CacheEntity();
$this->ratingListCache = $ratingListCache ?? self::createRatingListCache(Utils::transformCurrencies($allowedCurrencies), $client, $requestFactory);
$this->ratingListCache = $ratingListCache ?? self::createRatingListCache(Utils::transformCurrencies($allowedCurrencies), $client, $requestFactory, $tempDir);
}


Expand All @@ -44,11 +46,16 @@ public function __construct(
private static function createRatingListCache(
array $allowedCurrencies,
?ClientInterface $client,
?RequestFactoryInterface $requestFactory
?RequestFactoryInterface $requestFactory,
string|Dir|CacheLockingFactoryInterface $tempDir,
): RatingListCache
{
$cacheLockingFactory = $tempDir instanceof CacheLockingFactoryInterface
? $tempDir
: self::createCacheFactory($tempDir);

return new RatingListCache(
self::createCacheFactory()->create(),
$cacheLockingFactory->create(),
new SourceDownload($client ?? self::createClient(), $requestFactory ?? self::createRequestFactory(), $allowedCurrencies),
);
}
Expand All @@ -68,9 +75,9 @@ public function create(
}


private static function createCacheFactory(): CacheLockingFactoryInterface
private static function createCacheFactory(string|Dir $tempDir): CacheLockingFactoryInterface
{
return new CacheLockingFactory('exchange');
return new CacheLockingFactory($tempDir);
}


Expand Down

0 comments on commit 64c4dcd

Please sign in to comment.