Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit a9a7b73

Browse files
committed
Autoload replacer and make it configurable
1 parent 973077e commit a9a7b73

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

config/config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,18 @@
2929
\Jonassiewertsen\Livewire\Synthesizers\EntrySynthesizer::class,
3030
],
3131
],
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Replacers
36+
|--------------------------------------------------------------------------
37+
|
38+
| Define the replacers that will be used when static caching is enabled
39+
| to dynamically replace content within the response.
40+
|
41+
*/
42+
43+
'replacers' => [
44+
\Jonassiewertsen\Livewire\Replacers\AssetsReplacer::class,
45+
],
3246
];
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Jonassiewertsen\Livewire;
3+
namespace Jonassiewertsen\Livewire\Replacers;
44

55
use Illuminate\Http\Response;
66
use Illuminate\Support\Str;
@@ -9,7 +9,7 @@
99
use Livewire\Mechanisms\FrontendAssets\FrontendAssets;
1010
use Statamic\StaticCaching\Replacer;
1111

12-
class LivewireReplacer implements Replacer
12+
class AssetsReplacer implements Replacer
1313
{
1414
public function prepareResponseToCache(Response $responseToBeCached, Response $initialResponse)
1515
{

src/ServiceProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jonassiewertsen\Livewire;
44

55
use Livewire\Livewire;
6+
use Statamic\StaticCaching\Replacer;
67
use Statamic\Providers\AddonServiceProvider;
78

89
class ServiceProvider extends AddonServiceProvider
@@ -23,10 +24,19 @@ public function bootAddon(): void
2324
], 'statamic-livewire');
2425
}
2526

27+
$this->bootReplacers();
2628
$this->bootSyntesizers();
2729
}
2830

29-
protected function bootSyntesizers()
31+
protected function bootReplacers(): void
32+
{
33+
config()->set('statamic.static_caching.replacers', array_merge(
34+
config('statamic.static_caching.replacers'),
35+
config('statamic-livewire.replacers')
36+
));
37+
}
38+
39+
protected function bootSyntesizers(): void
3040
{
3141
if (! config('statamic-livewire.synthesizers.enabled', false)) {
3242
return;

0 commit comments

Comments
 (0)