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

Make cache store configurable #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions config/tailwind-merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
declare(strict_types=1);

return [
/*
|--------------------------------------------------------------------------
| Cache Store
|--------------------------------------------------------------------------
|
| Tailwind Merge uses Laravel's cache system to store the merged classes.
| Here you can customize the cache store that Tailwind Merge uses.
*/

'cache_store' => env('TAILWIND_MERGE_CACHE_STORE'),

/*
|--------------------------------------------------------------------------
| Prefix
Expand Down
14 changes: 12 additions & 2 deletions src/TailwindMergeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

namespace TailwindMerge\Laravel;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\ComponentAttributeBag;
use Psr\SimpleCache\CacheInterface;
use TailwindMerge\Contracts\TailwindMergeContract;
use TailwindMerge\TailwindMerge;

class TailwindMergeServiceProvider extends BaseServiceProvider
{
public function register(): void
{
$this->app->singleton(TailwindMergeContract::class, static fn (): TailwindMerge => TailwindMerge::factory()
$this->app->singleton(TailwindMergeContract::class, fn (): TailwindMerge => TailwindMerge::factory()
->withConfiguration(config('tailwind-merge', []))
->withCache(app('cache')->store()) // @phpstan-ignore-line
->withCache($this->getCacheStore())
->make());

$this->app->alias(TailwindMergeContract::class, 'tailwind-merge');
Expand Down Expand Up @@ -90,4 +92,12 @@ public function provides(): array
'tailwind-merge',
];
}

protected function getCacheStore(): CacheInterface
{
/** @var string|null $storage */
$storage = config('tailwind-merge.cache_store');

return Cache::store($storage);
}
}
2 changes: 2 additions & 0 deletions tests/Arch.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
->expect('TailwindMerge\Laravel\TailwindMergeServiceProvider')
->toOnlyUse([
'Illuminate\Contracts\Support\DeferrableProvider',
'Illuminate\Support\Facades\Cache',
'Illuminate\Support\ServiceProvider',
'Illuminate\View\Compilers\BladeCompiler',
'Illuminate\View\ComponentAttributeBag',
'Psr\SimpleCache\CacheInterface',
'TailwindMerge',

// helpers...
Expand Down
Loading