Skip to content

Commit 0797231

Browse files
authored
Merge pull request #152 from hotwired-laravel/laravel-12
Support Laravel 12
2 parents de5b875 + cec408b commit 0797231

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+708
-849
lines changed

.github/workflows/run-tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
os: [ubuntu-latest, macos-latest]
12-
php: [8.2]
13-
laravel: [10.*, 11.*]
11+
os: [ubuntu-latest]
12+
php: [8.2, 8.3, 8.4]
13+
laravel: [11.*, 12.*]
1414
stability: [prefer-lowest, prefer-stable]
1515
include:
16-
- laravel: 10.*
17-
testbench: 8.*
18-
workbench: 8.*
1916
- laravel: 11.*
2017
testbench: 9.*
2118
workbench: 9.*
19+
- laravel: 12.*
20+
testbench: 10.*
21+
workbench: 10.*
2222

2323
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2424

@@ -40,7 +40,7 @@ jobs:
4040
4141
- name: Install dependencies
4242
run: |
43-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/workbench:${{ matrix.workbench }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update
43+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/workbench:${{ matrix.workbench }}" --no-interaction --no-update
4444
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
4545
4646
- name: Execute tests

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
],
2020
"require": {
2121
"php": "^8.2",
22-
"illuminate/support": "^10.0|^11.0"
22+
"illuminate/support": "^11.0|^12.0"
2323
},
2424
"require-dev": {
2525
"laravel/pint": "^1.10",
26-
"orchestra/testbench": "^8.14|^9.0",
27-
"orchestra/workbench": "^8.0|^9.0",
28-
"phpunit/phpunit": "^10.5"
26+
"orchestra/testbench": "^9.0|^10.0",
27+
"orchestra/workbench": "^9.0|^10.0",
28+
"phpunit/phpunit": "^10.5|^11.5"
2929
},
3030
"autoload": {
3131
"psr-4": {

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\ValueObject\PhpVersion;
7+
8+
return RectorConfig::configure()
9+
->withPaths([
10+
__DIR__.'/src',
11+
__DIR__.'/tests',
12+
])
13+
->withPreparedSets(
14+
deadCode: true,
15+
codeQuality: true,
16+
typeDeclarations: true,
17+
privatization: true,
18+
earlyReturn: true,
19+
)
20+
->withAttributesSets()
21+
->withPhpSets()
22+
->withPhpVersion(PhpVersion::PHP_82);

src/Broadcasting/Factory.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function withoutBroadcasts(callable $callback)
4545
}
4646
}
4747

48-
public function fake()
48+
public function fake(): static
4949
{
5050
$this->recording = true;
5151

@@ -93,7 +93,7 @@ public function broadcastRefresh(Channel|Model|Collection|array|string|null $cha
9393
action: 'refresh',
9494
channel: $channel,
9595
attributes: array_filter(['request-id' => $requestId = Turbo::currentRequestId()]),
96-
)->lazyCancelIf(fn (PendingBroadcast $broadcast) => (
96+
)->lazyCancelIf(fn (PendingBroadcast $broadcast): bool => (
9797
$this->shouldLimitPageRefreshesOn($broadcast->channels, $requestId)
9898
));
9999
}
@@ -116,7 +116,7 @@ public function broadcastAction(string $action, $content = null, Model|string|nu
116116
return $broadcast->cancelIf(! $this->isBroadcasting);
117117
}
118118

119-
public function record(PendingBroadcast $broadcast)
119+
public function record(PendingBroadcast $broadcast): static
120120
{
121121
$this->recordedStreams[] = $broadcast;
122122

@@ -151,9 +151,7 @@ protected function resolveRendering($content)
151151
protected function resolveChannels(Channel|Model|Collection|array|string $channel)
152152
{
153153
if (is_array($channel) || $channel instanceof Collection) {
154-
return collect($channel)->flatMap(function ($channel) {
155-
return $this->resolveChannels($channel);
156-
})->values()->filter()->all();
154+
return collect($channel)->flatMap(fn ($channel) => $this->resolveChannels($channel))->values()->filter()->all();
157155
}
158156

159157
if (is_string($channel)) {
@@ -184,7 +182,7 @@ public function clearRecordedBroadcasts(): self
184182
return $this;
185183
}
186184

187-
public function assertBroadcasted($callback)
185+
public function assertBroadcasted(?callable $callback): static
188186
{
189187
$result = collect($this->recordedStreams)->filter($callback);
190188

@@ -193,7 +191,7 @@ public function assertBroadcasted($callback)
193191
return $this;
194192
}
195193

196-
public function assertBroadcastedTimes($callback, $times = 1, $message = null)
194+
public function assertBroadcastedTimes(?callable $callback, $times = 1, $message = null): static
197195
{
198196
$result = collect($this->recordedStreams)->filter($callback);
199197

@@ -210,8 +208,6 @@ public function assertBroadcastedTimes($callback, $times = 1, $message = null)
210208

211209
public function assertNothingWasBroadcasted()
212210
{
213-
return $this->assertBroadcastedTimes(function () {
214-
return true;
215-
}, 0, sprintf('Expected to not have broadcasted any Turbo Stream, but broadcasted %d instead.', count($this->recordedStreams)));
211+
return $this->assertBroadcastedTimes(fn (): true => true, 0, sprintf('Expected to not have broadcasted any Turbo Stream, but broadcasted %d instead.', count($this->recordedStreams)));
216212
}
217213
}

src/Broadcasting/PendingBroadcast.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ class PendingBroadcast
1818
/** @var Channel[] */
1919
public array $channels;
2020

21-
public string $action;
22-
23-
public ?string $target = null;
24-
25-
public ?string $targets = null;
26-
2721
public ?string $partialView = null;
2822

2923
public ?array $partialData = [];
@@ -32,8 +26,6 @@ class PendingBroadcast
3226

3327
public bool $escapeInlineContent = true;
3428

35-
public array $attributes = [];
36-
3729
/**
3830
* Whether we should broadcast only to other users and
3931
* ignore the current user's broadcasting socket.
@@ -61,7 +53,7 @@ class PendingBroadcast
6153
*
6254
* @var ?\HotwiredLaravel\TurboLaravel\Broadcasting\Factory = null
6355
*/
64-
protected $recorder = null;
56+
protected $recorder;
6557

6658
/**
6759
* These cancel callbacks will run right before the broadcasting is fired on __destruct.
@@ -70,13 +62,8 @@ class PendingBroadcast
7062
*/
7163
protected array $deferredCancelCallbacks = [];
7264

73-
public function __construct(array $channels, string $action, Rendering $rendering, ?string $target = null, ?string $targets = null, array $attributes = [])
65+
public function __construct(array $channels, public string $action, Rendering $rendering, public ?string $target = null, public ?string $targets = null, public array $attributes = [])
7466
{
75-
$this->action = $action;
76-
$this->target = $target;
77-
$this->targets = $targets;
78-
$this->attributes = $attributes;
79-
8067
$this->to($channels);
8168
$this->rendering($rendering);
8269
}
@@ -142,12 +129,12 @@ public function view(?string $view, array $data = []): self
142129
return $this->rendering(new Rendering($view, $data));
143130
}
144131

145-
public function content($content)
132+
public function content(\Illuminate\Contracts\View\View|\Illuminate\Support\HtmlString|string $content)
146133
{
147134
return $this->rendering(Rendering::forContent($content));
148135
}
149136

150-
public function attributes(array $attributes)
137+
public function attributes(array $attributes): static
151138
{
152139
$this->attributes = $attributes;
153140

@@ -170,7 +157,7 @@ public function method(?string $method = null): self
170157
return $this->attributes(Arr::except($this->attributes, 'method'));
171158
}
172159

173-
public function rendering(Rendering $rendering)
160+
public function rendering(Rendering $rendering): static
174161
{
175162
$this->partialView = $rendering->partial;
176163
$this->partialData = $rendering->data;
@@ -187,28 +174,28 @@ public function later(bool $later = true): self
187174
return $this;
188175
}
189176

190-
public function cancel()
177+
public function cancel(): static
191178
{
192179
$this->wasCancelled = true;
193180

194181
return $this;
195182
}
196183

197-
public function cancelIf($condition)
184+
public function cancelIf($condition): static
198185
{
199186
$this->wasCancelled = $this->wasCancelled || boolval(value($condition, $this));
200187

201188
return $this;
202189
}
203190

204-
public function lazyCancelIf(callable $condition)
191+
public function lazyCancelIf(callable $condition): static
205192
{
206193
$this->deferredCancelCallbacks[] = $condition;
207194

208195
return $this;
209196
}
210197

211-
public function fake($recorder = null)
198+
public function fake($recorder = null): static
212199
{
213200
$this->isRecording = true;
214201
$this->recorder = $recorder;

src/Broadcasting/Rendering.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,9 @@
99

1010
class Rendering
1111
{
12-
public ?string $partial = null;
12+
public function __construct(public ?string $partial = null, public ?array $data = [], public ?string $inlineContent = null, public bool $escapeInlineContent = true) {}
1313

14-
public ?array $data = [];
15-
16-
public ?string $inlineContent = null;
17-
18-
public bool $escapeInlineContent = true;
19-
20-
public function __construct(?string $partial = null, ?array $data = [], ?string $inlineContent = null, ?bool $escapeInlineContent = true)
21-
{
22-
$this->partial = $partial;
23-
$this->data = $data;
24-
$this->inlineContent = $inlineContent;
25-
$this->escapeInlineContent = $escapeInlineContent;
26-
}
27-
28-
public static function forContent(View|HtmlString|string $content)
14+
public static function forContent(View|HtmlString|string $content): static
2915
{
3016
if ($content instanceof View) {
3117
return new static(partial: $content->name(), data: $content->getData());

src/Commands/TurboInstallCommand.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TurboInstallCommand extends Command
1616

1717
public $description = 'Installs Turbo.';
1818

19-
public function handle()
19+
public function handle(): void
2020
{
2121
$this->updateLayouts();
2222
$this->publishJsFiles();
@@ -26,7 +26,7 @@ public function handle()
2626
$this->components->info('Turbo Laravel was installed successfully.');
2727
}
2828

29-
private function publishJsFiles()
29+
private function publishJsFiles(): void
3030
{
3131
File::ensureDirectoryExists(resource_path('js/elements'));
3232
File::ensureDirectoryExists(resource_path('js/libs'));
@@ -38,7 +38,7 @@ private function publishJsFiles()
3838
File::put(resource_path('js/libs/index.js'), $this->libsIndexJsImportLines());
3939
}
4040

41-
private function appJsImportLines()
41+
private function appJsImportLines(): string
4242
{
4343
$prefix = $this->usingImportmaps() ? '' : './';
4444

@@ -51,7 +51,7 @@ private function appJsImportLines()
5151
return implode("\n", $imports);
5252
}
5353

54-
private function libsIndexJsImportLines()
54+
private function libsIndexJsImportLines(): string
5555
{
5656
$imports = [];
5757

@@ -62,7 +62,7 @@ private function libsIndexJsImportLines()
6262
return implode("\n", $imports);
6363
}
6464

65-
private function installJsDependencies()
65+
private function installJsDependencies(): void
6666
{
6767
if ($this->usingImportmaps()) {
6868
$this->updateImportmapsDependencies();
@@ -74,9 +74,7 @@ private function installJsDependencies()
7474

7575
private function updateNpmDependencies(): void
7676
{
77-
$this->updateNodePackages(function ($packages) {
78-
return $this->jsDependencies() + $packages;
79-
});
77+
static::updateNodePackages(fn ($packages): array => $this->jsDependencies() + $packages);
8078
}
8179

8280
private function runInstallAndBuildCommand(): void
@@ -92,7 +90,7 @@ private function runInstallAndBuildCommand(): void
9290
}
9391
}
9492

95-
private function runCommands($commands): void
93+
private function runCommands(array $commands): void
9694
{
9795
$process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null);
9896

@@ -104,7 +102,7 @@ private function runCommands($commands): void
104102
}
105103
}
106104

107-
$process->run(function ($type, $line) {
105+
$process->run(function ($type, string $line): void {
108106
$this->output->write(' '.$line);
109107
});
110108
}
@@ -174,7 +172,7 @@ private function existingLayoutFiles()
174172
->filter(fn ($file) => File::exists($file));
175173
}
176174

177-
private function phpBinary()
175+
private function phpBinary(): string
178176
{
179177
return (new PhpExecutableFinder)->find(false) ?: 'php';
180178
}

0 commit comments

Comments
 (0)