Skip to content

Commit

Permalink
Merge pull request #152 from hotwired-laravel/laravel-12
Browse files Browse the repository at this point in the history
Support Laravel 12
  • Loading branch information
tonysm authored Mar 2, 2025
2 parents de5b875 + cec408b commit 0797231
Show file tree
Hide file tree
Showing 48 changed files with 708 additions and 849 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
php: [8.2]
laravel: [10.*, 11.*]
os: [ubuntu-latest]
php: [8.2, 8.3, 8.4]
laravel: [11.*, 12.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
workbench: 8.*
- laravel: 11.*
testbench: 9.*
workbench: 9.*
- laravel: 12.*
testbench: 10.*
workbench: 10.*

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

Expand All @@ -40,7 +40,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/workbench:${{ matrix.workbench }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/workbench:${{ matrix.workbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
],
"require": {
"php": "^8.2",
"illuminate/support": "^10.0|^11.0"
"illuminate/support": "^11.0|^12.0"
},
"require-dev": {
"laravel/pint": "^1.10",
"orchestra/testbench": "^8.14|^9.0",
"orchestra/workbench": "^8.0|^9.0",
"phpunit/phpunit": "^10.5"
"orchestra/testbench": "^9.0|^10.0",
"orchestra/workbench": "^9.0|^10.0",
"phpunit/phpunit": "^10.5|^11.5"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withPreparedSets(
deadCode: true,
codeQuality: true,
typeDeclarations: true,
privatization: true,
earlyReturn: true,
)
->withAttributesSets()
->withPhpSets()
->withPhpVersion(PhpVersion::PHP_82);
18 changes: 7 additions & 11 deletions src/Broadcasting/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function withoutBroadcasts(callable $callback)
}
}

public function fake()
public function fake(): static
{
$this->recording = true;

Expand Down Expand Up @@ -93,7 +93,7 @@ public function broadcastRefresh(Channel|Model|Collection|array|string|null $cha
action: 'refresh',
channel: $channel,
attributes: array_filter(['request-id' => $requestId = Turbo::currentRequestId()]),
)->lazyCancelIf(fn (PendingBroadcast $broadcast) => (
)->lazyCancelIf(fn (PendingBroadcast $broadcast): bool => (
$this->shouldLimitPageRefreshesOn($broadcast->channels, $requestId)
));
}
Expand All @@ -116,7 +116,7 @@ public function broadcastAction(string $action, $content = null, Model|string|nu
return $broadcast->cancelIf(! $this->isBroadcasting);
}

public function record(PendingBroadcast $broadcast)
public function record(PendingBroadcast $broadcast): static
{
$this->recordedStreams[] = $broadcast;

Expand Down Expand Up @@ -151,9 +151,7 @@ protected function resolveRendering($content)
protected function resolveChannels(Channel|Model|Collection|array|string $channel)
{
if (is_array($channel) || $channel instanceof Collection) {
return collect($channel)->flatMap(function ($channel) {
return $this->resolveChannels($channel);
})->values()->filter()->all();
return collect($channel)->flatMap(fn ($channel) => $this->resolveChannels($channel))->values()->filter()->all();
}

if (is_string($channel)) {
Expand Down Expand Up @@ -184,7 +182,7 @@ public function clearRecordedBroadcasts(): self
return $this;
}

public function assertBroadcasted($callback)
public function assertBroadcasted(?callable $callback): static
{
$result = collect($this->recordedStreams)->filter($callback);

Expand All @@ -193,7 +191,7 @@ public function assertBroadcasted($callback)
return $this;
}

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

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

public function assertNothingWasBroadcasted()
{
return $this->assertBroadcastedTimes(function () {
return true;
}, 0, sprintf('Expected to not have broadcasted any Turbo Stream, but broadcasted %d instead.', count($this->recordedStreams)));
return $this->assertBroadcastedTimes(fn (): true => true, 0, sprintf('Expected to not have broadcasted any Turbo Stream, but broadcasted %d instead.', count($this->recordedStreams)));
}
}
31 changes: 9 additions & 22 deletions src/Broadcasting/PendingBroadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ class PendingBroadcast
/** @var Channel[] */
public array $channels;

public string $action;

public ?string $target = null;

public ?string $targets = null;

public ?string $partialView = null;

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

public bool $escapeInlineContent = true;

public array $attributes = [];

/**
* Whether we should broadcast only to other users and
* ignore the current user's broadcasting socket.
Expand Down Expand Up @@ -61,7 +53,7 @@ class PendingBroadcast
*
* @var ?\HotwiredLaravel\TurboLaravel\Broadcasting\Factory = null
*/
protected $recorder = null;
protected $recorder;

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

public function __construct(array $channels, string $action, Rendering $rendering, ?string $target = null, ?string $targets = null, array $attributes = [])
public function __construct(array $channels, public string $action, Rendering $rendering, public ?string $target = null, public ?string $targets = null, public array $attributes = [])
{
$this->action = $action;
$this->target = $target;
$this->targets = $targets;
$this->attributes = $attributes;

$this->to($channels);
$this->rendering($rendering);
}
Expand Down Expand Up @@ -142,12 +129,12 @@ public function view(?string $view, array $data = []): self
return $this->rendering(new Rendering($view, $data));
}

public function content($content)
public function content(\Illuminate\Contracts\View\View|\Illuminate\Support\HtmlString|string $content)
{
return $this->rendering(Rendering::forContent($content));
}

public function attributes(array $attributes)
public function attributes(array $attributes): static
{
$this->attributes = $attributes;

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

public function rendering(Rendering $rendering)
public function rendering(Rendering $rendering): static
{
$this->partialView = $rendering->partial;
$this->partialData = $rendering->data;
Expand All @@ -187,28 +174,28 @@ public function later(bool $later = true): self
return $this;
}

public function cancel()
public function cancel(): static
{
$this->wasCancelled = true;

return $this;
}

public function cancelIf($condition)
public function cancelIf($condition): static
{
$this->wasCancelled = $this->wasCancelled || boolval(value($condition, $this));

return $this;
}

public function lazyCancelIf(callable $condition)
public function lazyCancelIf(callable $condition): static
{
$this->deferredCancelCallbacks[] = $condition;

return $this;
}

public function fake($recorder = null)
public function fake($recorder = null): static
{
$this->isRecording = true;
$this->recorder = $recorder;
Expand Down
18 changes: 2 additions & 16 deletions src/Broadcasting/Rendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,9 @@

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

public ?array $data = [];

public ?string $inlineContent = null;

public bool $escapeInlineContent = true;

public function __construct(?string $partial = null, ?array $data = [], ?string $inlineContent = null, ?bool $escapeInlineContent = true)
{
$this->partial = $partial;
$this->data = $data;
$this->inlineContent = $inlineContent;
$this->escapeInlineContent = $escapeInlineContent;
}

public static function forContent(View|HtmlString|string $content)
public static function forContent(View|HtmlString|string $content): static
{
if ($content instanceof View) {
return new static(partial: $content->name(), data: $content->getData());
Expand Down
20 changes: 9 additions & 11 deletions src/Commands/TurboInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TurboInstallCommand extends Command

public $description = 'Installs Turbo.';

public function handle()
public function handle(): void
{
$this->updateLayouts();
$this->publishJsFiles();
Expand All @@ -26,7 +26,7 @@ public function handle()
$this->components->info('Turbo Laravel was installed successfully.');
}

private function publishJsFiles()
private function publishJsFiles(): void
{
File::ensureDirectoryExists(resource_path('js/elements'));
File::ensureDirectoryExists(resource_path('js/libs'));
Expand All @@ -38,7 +38,7 @@ private function publishJsFiles()
File::put(resource_path('js/libs/index.js'), $this->libsIndexJsImportLines());
}

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

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

private function libsIndexJsImportLines()
private function libsIndexJsImportLines(): string
{
$imports = [];

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

private function installJsDependencies()
private function installJsDependencies(): void
{
if ($this->usingImportmaps()) {
$this->updateImportmapsDependencies();
Expand All @@ -74,9 +74,7 @@ private function installJsDependencies()

private function updateNpmDependencies(): void
{
$this->updateNodePackages(function ($packages) {
return $this->jsDependencies() + $packages;
});
static::updateNodePackages(fn ($packages): array => $this->jsDependencies() + $packages);
}

private function runInstallAndBuildCommand(): void
Expand All @@ -92,7 +90,7 @@ private function runInstallAndBuildCommand(): void
}
}

private function runCommands($commands): void
private function runCommands(array $commands): void
{
$process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null);

Expand All @@ -104,7 +102,7 @@ private function runCommands($commands): void
}
}

$process->run(function ($type, $line) {
$process->run(function ($type, string $line): void {
$this->output->write(' '.$line);
});
}
Expand Down Expand Up @@ -174,7 +172,7 @@ private function existingLayoutFiles()
->filter(fn ($file) => File::exists($file));
}

private function phpBinary()
private function phpBinary(): string
{
return (new PhpExecutableFinder)->find(false) ?: 'php';
}
Expand Down
Loading

0 comments on commit 0797231

Please sign in to comment.