Skip to content

Commit

Permalink
feat: add support for setting cache store (#14)
Browse files Browse the repository at this point in the history
This adds support for setting the cache store with the `cache` driver.

---------

Co-authored-by: Owen Voke <development@voke.dev>
  • Loading branch information
olivernybroe and owenvoke committed Mar 21, 2024
1 parent d843151 commit ef679a3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 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
12 changes: 6 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
parameters:
ignoreErrors:
-
message: "#^Illuminate\\\\Support\\\\Facades\\\\Blade facade should not be used\\.$#"
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Commands/ViewLatestRatesCommand.php
path: src/ExchangeRateProviders/FixerProvider.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
message: "#^Cannot call method timezone\\(\\) on Carbon\\\\CarbonImmutable\\|null\\.$#"
count: 1
path: src/ExchangeRateProviders/FixerProvider.php
path: src/ExchangeRateProviders/FrankfurterProvider.php

-
message: "#^Worksome\\\\Exchange\\\\Facades\\\\Exchange facade should not be used\\.$#"
message: "#^Strict comparison using \\=\\=\\= between Carbon\\\\CarbonImmutable\\|null and false will always evaluate to false\\.$#"
count: 1
path: src/Facades/Exchange.php
path: src/ExchangeRateProviders/FrankfurterProvider.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/ViewLatestRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Worksome\Exchange\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Blade;
use Illuminate\View\Compilers\BladeCompiler;
use Worksome\Exchange\Commands\Concerns\HasUsefulConsoleMethods;
use Worksome\Exchange\Contracts\CurrencyCodeProvider;
use Worksome\Exchange\Exceptions\InvalidCurrencyCodeException;
Expand Down Expand Up @@ -66,7 +66,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 ef679a3

Please sign in to comment.