Skip to content

Commit ffc2728

Browse files
authored
Laravel 12 (#1)
* Add support for Laravel 12 * Fix typo * Rename config file * Add 🍺 and run formatting * Apply formatting and cleanup
1 parent da525a5 commit ffc2728

10 files changed

+70
-48
lines changed

composer.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"require": {
3232
"php": "^8.1",
33-
"illuminate/support": "^10.0|^11.0",
33+
"illuminate/support": "^10.0|^11.0|^12.0",
3434
"statamic/cms": "^4.23.2|^5.0",
3535
"livewire/livewire": "^3.0"
3636
},
@@ -44,5 +44,13 @@
4444
"MarcoRieser\\Livewire\\ServiceProvider"
4545
]
4646
}
47+
},
48+
"config": {
49+
"allow-plugins": {
50+
"pixelfear/composer-dist-plugin": true
51+
}
52+
},
53+
"require-dev": {
54+
"laravel/pint": "^1.21"
4755
}
4856
}

config/config.php config/statamic-livewire.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
| It's recommended to remove or uncomment those synthesizers that are
1515
| not used in your application, to avoid overhead by loading those.
1616
|
17-
| This features is experimental. It's ment to be tested and to played
17+
| This features is experimental. It's meant to be tested and to played
1818
| with. As long as it is experimental, it can be changed and removed
1919
| at any point without a warning.
2020
|

src/Replacers/AssetsReplacer.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
class AssetsReplacer implements Replacer
1414
{
15-
public function prepareResponseToCache(Response $responseToBeCached, Response $initialResponse)
15+
public function prepareResponseToCache(Response $response, Response $initial): void
1616
{
17-
if (! $content = $responseToBeCached->getContent()) {
17+
if (! $content = $response->getContent()) {
1818
return;
1919
}
2020

21-
// Don't disturb Livewire's assets injection when caching is off.
21+
// Don't disturb Livewires assets injection when caching is off.
2222
if (app(Cacher::class) instanceof NullCacher) {
2323
return;
2424
}
@@ -47,19 +47,21 @@ public function prepareResponseToCache(Response $responseToBeCached, Response $i
4747
app(FrontendAssets::class)->hasRenderedScripts = false;
4848
}
4949

50-
$responseToBeCached->setContent(
50+
$response->setContent(
5151
SupportAutoInjectedAssets::injectAssets($content, $assetsHead, $assetsBody)
5252
);
5353
}
5454

55-
protected function shouldInjectLivewireAssets()
55+
protected function shouldInjectLivewireAssets(): bool
5656
{
5757
if (! SupportAutoInjectedAssets::$forceAssetInjection && config('livewire.inject_assets', true) === false) {
5858
return false;
5959
}
60+
6061
if ((! SupportAutoInjectedAssets::$hasRenderedAComponentThisRequest) && (! SupportAutoInjectedAssets::$forceAssetInjection)) {
6162
return false;
6263
}
64+
6365
if (app(FrontendAssets::class)->hasRenderedScripts) {
6466
return false;
6567
}

src/ServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class ServiceProvider extends AddonServiceProvider
1515

1616
public function bootAddon(): void
1717
{
18-
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'statamic-livewire');
18+
$this->mergeConfigFrom(__DIR__.'/../config/statamic-livewire.php', 'statamic-livewire');
1919

2020
if ($this->app->runningInConsole()) {
2121
$this->publishes([
22-
__DIR__.'/../config/config.php' => config_path('statamic-livewire.php'),
22+
__DIR__.'/../config/statamic-livewire.php' => config_path('statamic-livewire.php'),
2323
], 'statamic-livewire');
2424
}
2525

src/Synthesizers/EntryCollectionSynthesizer.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33
namespace MarcoRieser\Livewire\Synthesizers;
44

5+
use Carbon\CarbonInterface;
56
use Illuminate\Support\Carbon;
67
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
7-
use Statamic\Entries\Entry;
88
use Statamic\Entries\EntryCollection as StatamicEntryCollection;
9+
use Statamic\Facades\Entry;
910

1011
class EntryCollectionSynthesizer extends Synth
1112
{
12-
public static $key = 'statamic-entry-collection';
13+
public static string $key = 'statamic-entry-collection';
1314

14-
public static function match($target)
15+
public static function match($target): bool
1516
{
1617
return $target instanceof StatamicEntryCollection;
1718
}
1819

19-
public function dehydrate($target)
20+
public function dehydrate($target): array
2021
{
2122
$data = [];
2223

@@ -33,7 +34,7 @@ public function dehydrate($target)
3334
return [$data, []];
3435
}
3536

36-
public function hydrate($values)
37+
public function hydrate($values): StatamicEntryCollection
3738
{
3839
$items = [];
3940

@@ -47,11 +48,11 @@ public function hydrate($values)
4748
if ($value['date']) {
4849
$date = $value['date'];
4950

50-
if (! $date instanceof \Carbon\CarbonInterface) {
51+
if (! $date instanceof CarbonInterface) {
5152
$date = Carbon::parse($date);
5253
}
5354

54-
$entry->date($date ?? null);
55+
$entry->date($date);
5556
}
5657

5758
$items[] = $entry;

src/Synthesizers/EntrySynthesizer.php

+17-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
namespace MarcoRieser\Livewire\Synthesizers;
44

5+
use Carbon\CarbonInterface;
6+
use Illuminate\Support\Carbon;
57
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
6-
use Statamic\Entries\Entry as StatamicEntry;
7-
use Statamic\Facades\Entry;
8+
use Statamic\Contracts\Entries\Entry;
9+
use Statamic\Facades\Entry as EntryFacade;
810

911
class EntrySynthesizer extends Synth
1012
{
11-
public static $key = 'statamic-entry';
13+
public static string $key = 'statamic-entry';
1214

13-
public static function match($target)
15+
public static function match($target): bool
1416
{
15-
return $target instanceof StatamicEntry;
17+
return $target instanceof Entry;
1618
}
1719

18-
public function dehydrate($entry)
20+
public function dehydrate(Entry $entry): array
1921
{
2022
return [
2123
[
@@ -27,16 +29,22 @@ public function dehydrate($entry)
2729
], []];
2830
}
2931

30-
public function hydrate($value)
32+
public function hydrate($value): Entry
3133
{
32-
$entry = Entry::make()
34+
$entry = EntryFacade::make()
3335
->id($value['id'])
3436
->slug($value['slug'] ?? null)
3537
->collection($value['collection'] ?? null)
3638
->data($value['data']);
3739

3840
if ($value['date']) {
39-
$entry->date($value['date'] ?? null);
41+
$date = $value['date'];
42+
43+
if (! $date instanceof CarbonInterface) {
44+
$date = Carbon::parse($date);
45+
}
46+
47+
$entry->date($date);
4048
}
4149

4250
return $entry;

src/Synthesizers/FieldSynthesizer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
class FieldSynthesizer extends Synth
99
{
10-
public static $key = 'statamic-field';
10+
public static string $key = 'statamic-field';
1111

12-
public static function match($target)
12+
public static function match($target): bool
1313
{
1414
return $target instanceof Field;
1515
}
1616

17-
public function dehydrate($target, $dehydrateChild)
17+
public function dehydrate($target, $dehydrateChild): array
1818
{
1919
$data = [
2020
'handle' => $target->handle(),
@@ -28,7 +28,7 @@ public function dehydrate($target, $dehydrateChild)
2828
return [$data, []];
2929
}
3030

31-
public function hydrate($value, $meta, $hydrateChild)
31+
public function hydrate($value, $meta, $hydrateChild): Field
3232
{
3333
foreach ($value as $key => $child) {
3434
$value[$key] = $hydrateChild($key, $child);

src/Synthesizers/FieldtypeSynthesizer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
class FieldtypeSynthesizer extends Synth
99
{
10-
public static $key = 'statamic-fieldtype';
10+
public static string $key = 'statamic-fieldtype';
1111

12-
public static function match($target)
12+
public static function match($target): bool
1313
{
1414
return $target instanceof Fieldtype;
1515
}
1616

17-
public function dehydrate($target, $dehydrateChild)
17+
public function dehydrate($target, $dehydrateChild): array
1818
{
1919
$data = [
2020
'field' => $target->field(),

src/Synthesizers/ValueSynthesizer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
class ValueSynthesizer extends Synth
1111
{
12-
public static $key = 'statamic-value';
12+
public static string $key = 'statamic-value';
1313

14-
public static function match($target)
14+
public static function match($target): bool
1515
{
1616
return $target instanceof Value;
1717
}
1818

19-
public function dehydrate($target, $dehydrateChild)
19+
public function dehydrate($target, $dehydrateChild): array
2020
{
2121
$value = invade($target);
2222

@@ -35,7 +35,7 @@ public function dehydrate($target, $dehydrateChild)
3535
return [$data, []];
3636
}
3737

38-
public function hydrate($value, $meta, $hydrateChild)
38+
public function hydrate($value, $meta, $hydrateChild): Value
3939
{
4040
foreach ($value as $key => $child) {
4141
$value[$key] = $hydrateChild($key, $child);

src/Tags/Livewire.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace MarcoRieser\Livewire\Tags;
44

5+
use Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets;
6+
use Livewire\Mechanisms\FrontendAssets\FrontendAssets;
57
use Statamic\Tags\Tags;
8+
use function Livewire\store;
69

710
class Livewire extends Tags
811
{
@@ -37,13 +40,13 @@ public function entangle(): string
3740
$modifier = $this->params->get('modifier');
3841
$instanceId = $this->context['__livewire']->getId();
3942

40-
$expression = ".entangle('{$property}')";
43+
$expression = ".entangle('$property')";
4144

4245
if ($modifier) {
43-
$expression .= ".{$modifier}";
46+
$expression .= ".$modifier";
4447
}
4548

46-
return "window.Livewire.find('$instanceId'){$expression}";
49+
return "window.Livewire.find('$instanceId')$expression";
4750
}
4851

4952
/**
@@ -57,14 +60,14 @@ public function this(): string
5760
$instanceId = $this->context['__livewire']->getId();
5861

5962
if (! count($this->params)) {
60-
return "window.Livewire.find('{$instanceId}')";
63+
return "window.Livewire.find('$instanceId')";
6164
}
6265

6366
$action = $this->params->take(1)->toArray();
6467
$method = key($action);
6568
$parameters = reset($action);
6669

67-
return "window.Livewire.find('{$instanceId}').{$method}{$parameters}";
70+
return "window.Livewire.find('$instanceId').$method$parameters";
6871
}
6972

7073
/**
@@ -74,7 +77,7 @@ public function this(): string
7477
*/
7578
public function styles(): string
7679
{
77-
return \Livewire\Mechanisms\FrontendAssets\FrontendAssets::styles();
80+
return FrontendAssets::styles();
7881
}
7982

8083
/**
@@ -84,7 +87,7 @@ public function styles(): string
8487
*/
8588
public function scripts(): string
8689
{
87-
return \Livewire\Mechanisms\FrontendAssets\FrontendAssets::scripts();
90+
return FrontendAssets::scripts();
8891
}
8992

9093
/**
@@ -94,7 +97,7 @@ public function scripts(): string
9497
*/
9598
public function scriptConfig(): string
9699
{
97-
return \Livewire\Mechanisms\FrontendAssets\FrontendAssets::scriptConfig();
100+
return FrontendAssets::scriptConfig();
98101
}
99102

100103
/**
@@ -108,11 +111,11 @@ public function assets(): void
108111

109112
$key = md5($html);
110113

111-
if (in_array($key, \Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets::$alreadyRunAssetKeys)) {
114+
if (in_array($key, SupportScriptsAndAssets::$alreadyRunAssetKeys)) {
112115
// Skip it...
113116
} else {
114-
\Livewire\Features\SupportScriptsAndAssets\SupportScriptsAndAssets::$alreadyRunAssetKeys[] = $key;
115-
\Livewire\store($this->context['__livewire'])->push('assets', $html, $key);
117+
SupportScriptsAndAssets::$alreadyRunAssetKeys[] = $key;
118+
store($this->context['__livewire'])->push('assets', $html, $key);
116119
}
117120
}
118121

@@ -127,6 +130,6 @@ public function script(): void
127130

128131
$key = md5($html);
129132

130-
\Livewire\store($this->context['__livewire'])->push('scripts', $html, $key);
133+
store($this->context['__livewire'])->push('scripts', $html, $key);
131134
}
132135
}

0 commit comments

Comments
 (0)