Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for setting cache store #14

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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