Skip to content

Commit

Permalink
feat: Add support for setting cache store
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver committed Feb 6, 2023
1 parent 782ba46 commit 622ebfe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'strategy' => 'exchange_rate',
'ttl' => 60 * 60 * 24, // 24 hours
'key' => 'cached_exchange_rates',
'store' => null,
],
],

Expand Down
4 changes: 3 additions & 1 deletion src/Commands/ViewLatestRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Blade;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Compilers\CompilerInterface;
use Worksome\Exchange\Commands\Concerns\HasUsefulConsoleMethods;
use Worksome\Exchange\Contracts\CurrencyCodeProvider;
use Worksome\Exchange\Exceptions\InvalidCurrencyCodeException;
Expand Down Expand Up @@ -66,7 +68,7 @@ private function data(CurrencyCodeProvider $currencyCodeProvider): array

private function renderRates(Rates $rates): void
{
render(Blade::render(<<<'HTML'
render(BladeCompiler::render(<<<'HTML'
<div class="mx-2 mt-1 space-y-1">
<header class="w-full max-w-90 text-center py-1 bg-green-500 font-bold text-gray-50">
Exchange rates based on 1 {{ $baseCurrency }}
Expand Down
6 changes: 5 additions & 1 deletion src/Facades/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ final class Exchange extends Facade
*/
public static function fake(array $rates = []): void
{
/** @var \Worksome\Exchange\Exchange $fake */

/**
* @var \Worksome\Exchange\Exchange $fake
* @phpstan-ignore-next-line
*/
$fake = self::$app->instance(\Worksome\Exchange\Exchange::class, self::getFacadeRoot());

$fake->fake($rates);
Expand Down
7 changes: 6 additions & 1 deletion src/Support/ExchangeRateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Worksome\Exchange\Support;

use Illuminate\Cache\Repository;
use Illuminate\Contracts\Cache\Factory as CacheFactory;
use Illuminate\Http\Client\Factory;
use Illuminate\Support\Manager;
use Worksome\Exchange\Exceptions\InvalidConfigurationException;
Expand Down Expand Up @@ -56,8 +57,12 @@ public function createFrankfurterDriver(): FrankfurterProvider

public function createCacheDriver(): CachedProvider
{
/** @var CacheFactory $factory */
$factory = $this->container->make(CacheFactory::class);

return new CachedProvider(
$this->container->make(Repository::class),
// @phpstan-ignore-next-line
$factory->store($this->config->get('exchange.services.cache.store')),
// @phpstan-ignore-next-line
$this->driver($this->config->get('exchange.services.cache.strategy')),
strval($this->config->get('exchange.services.cache.key', 'cached_exchange_rates')),
Expand Down

0 comments on commit 622ebfe

Please sign in to comment.