repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Entangle/ToggleEntangled.php
legacy_tests/Browser/Alpine/Entangle/ToggleEntangled.php
<?php namespace LegacyTests\Browser\Alpine\Entangle; use Livewire\Component as BaseComponent; class ToggleEntangled extends BaseComponent { public $active = false; public function render() { return <<<'HTML' <div> <div x-data="{ active: @entangle('active').live }"> <div dusk="output.alpine" x-text="active"></div> <div dusk="output.livewire">{{ $active ? 'true' : 'false' }}</div> <button dusk="toggle" x-on:click="active = !active">Toggle Active</button> </div> </div> HTML; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Entangle/EntangleNestedParentComponent.php
legacy_tests/Browser/Alpine/Entangle/EntangleNestedParentComponent.php
<?php namespace LegacyTests\Browser\Alpine\Entangle; use Livewire\Component as BaseComponent; class EntangleNestedParentComponent extends BaseComponent { public $list = [ ['id' => 1, 'name' => 'test1'], ]; public function addList() { $this->list[] = ['id' => (count($this->list) + 1), 'name' => 'test' . (count($this->list) + 1)]; } public function removeList() { array_pop($this->list); } public function render() { return <<<'HTML' <div x-data> <div dusk="output"> @foreach($list as $key => $item) @livewire(LegacyTests\Browser\Alpine\Entangle\EntangleNestedChildComponent::class, ['item' => $item], key($key)) @endforeach </div> <div> <button dusk="add" type="button" wire:click="addList">Add</button> <button dusk="remove" type="button" wire:click="removeList">Delete</button> </div> </div> HTML; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Entangle/EntangleResponseCheck.php
legacy_tests/Browser/Alpine/Entangle/EntangleResponseCheck.php
<?php namespace LegacyTests\Browser\Alpine\Entangle; use Livewire\Component as BaseComponent; class EntangleResponseCheck extends BaseComponent { public $list = [ ['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ]; public $listUpdatedByAlpine = false; public function addList() { $this->list[] = ['id' => count($this->list)]; } public function updatedList() { $this->listUpdatedByAlpine = true; } public function render() { return <<<'HTML' <div> <div x-data="{ list: $wire.entangle('list') }"> <div dusk="output">{{ $listUpdatedByAlpine ? 'true' : 'false' }}</div> </div> <div> <button dusk="add" type="button" wire:click="addList">Add</button> </div> </div> HTML; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Entangle/view.blade.php
legacy_tests/Browser/Alpine/Entangle/view.blade.php
<div> <div x-data="{ items: @entangle('items').live }"> <button @click="items.push('baz')" dusk="button">Add Baz</button> <div dusk="output.alpine"> <h1>JavaScript List:</h1> <template x-for="item in items"> <div x-text="item"></div> </template> </div> <div dusk="output.blade"> <h1>Server rendered List:</h1> @foreach($items as $item) <div>{{ $item }}</div> @endforeach </div> </div> <div x-data> <button wire:click="$set('showBob', true)" dusk="bob.show">Show Bob</button> <div dusk="bob.blade">{{ $bob }}</div> <div> @if ($showBob) <div x-data="{ bob: @entangle('bob').live }"> <button x-on:click="bob = 'after'" dusk="bob.button">Change Bob</button> <div dusk="bob.alpine" x-text="bob"></div> </div> @endif </div> </div> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Entangle/Component.php
legacy_tests/Browser/Alpine/Entangle/Component.php
<?php namespace LegacyTests\Browser\Alpine\Entangle; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class Component extends BaseComponent { public $items = ['foo', 'bar']; public $showBob = false; public $bob = 'before'; public function render() { return View::file(__DIR__.'/view.blade.php'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Transition/EntangleComponent.php
legacy_tests/Browser/Alpine/Transition/EntangleComponent.php
<?php namespace LegacyTests\Browser\Alpine\Transition; use Livewire\Component as BaseComponent; class EntangleComponent extends BaseComponent { public $show = true; public $changeDom = false; public function render() { return <<<'EOD' <div> <div x-data="{ show: @entangle('show').live }"> <button x-on:click="show = ! show" dusk="button">Toggle</button> <button wire:click="$toggle('changeDom')" dusk="change-dom">Change DOM</button> <div x-show="show" dusk="outer"> <div x-show.transition.duration.250ms="show" x-transition.duration.250ms dusk="inner"> <h1>@if ($changeDom) @json($show) @else static-filler @endif</h1> </div> </div> </div> </div> EOD; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Transition/DollarSignWireComponent.php
legacy_tests/Browser/Alpine/Transition/DollarSignWireComponent.php
<?php namespace LegacyTests\Browser\Alpine\Transition; use Livewire\Component as BaseComponent; class DollarSignWireComponent extends BaseComponent { public $show = true; public $changeDom = false; public function render() { return <<<'EOD' <div> <div x-data> <button wire:click="$toggle('show')" dusk="button">Toggle</button> <button wire:click="$toggle('changeDom')" dusk="change-dom">Change DOM</button> <div x-show="$wire.show" dusk="outer"> <div x-show.transition.duration.250ms="$wire.show" x-transition.duration.250ms dusk="inner"> <h1>@if ($changeDom) @json($show) @else static-filler @endif</h1> </div> </div> </div> </div> EOD; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Transition/Test.php
legacy_tests/Browser/Alpine/Transition/Test.php
<?php namespace LegacyTests\Browser\Alpine\Transition; use LegacyTests\Browser\TestCase; class Test extends TestCase { public function setUp(): void { if (isset($_SERVER['CI'])) { $this->markTestSkipped('These tests can be flaky during CI. Have skipped, but need to ensure we run locally before release.'); } parent::setUp(); } public function test_dollar_sign_wire() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, DollarSignWireComponent::class); $this->runThroughTransitions($browser); $browser->waitForLivewire()->click('@change-dom'); $this->runThroughTransitions($browser); }); } public function test_entangle() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, EntangleComponent::class); $this->runThroughTransitions($browser); $browser->waitForLivewire()->click('@change-dom'); $this->runThroughTransitions($browser); }); } public function test_dot_defer() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, EntangleDeferComponent::class); // Because this is .defer, we want to mix Alpine and Livewire toggles. $this->runThroughTransitions($browser, 'button', 'button'); $this->runThroughTransitions($browser, 'livewire-button', 'livewire-button'); $this->runThroughTransitions($browser, 'button', 'livewire-button'); $browser->pause(500); $this->runThroughTransitions($browser, 'livewire-button', 'button'); $browser->waitForLivewire()->click('@change-dom'); $this->runThroughTransitions($browser, 'button', 'button'); $this->runThroughTransitions($browser, 'livewire-button', 'livewire-button'); $this->runThroughTransitions($browser, 'button', 'livewire-button'); $this->runThroughTransitions($browser, 'livewire-button', 'button'); }); } protected function runThroughTransitions($browser, $firstHook = 'button', $secondHook = 'button') { return $browser // Transition out ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', '') ->click('@'.$firstHook) ->pause(100) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.opacity', '0') ->pause(250) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', 'none') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', 'none') // Transition back in ->click('@'.$secondHook) ->pause(100) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.opacity', '1') ->pause(250) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', '') // Transition out, but interrupt mid-way, then go back ->click('@'.$firstHook) ->pause(100) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.opacity', '0') ->click('@'.$secondHook) ->pause(100) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.opacity', '1') ->pause(250) ->assertScript('document.querySelector(\'[dusk="outer"]\').style.display', '') ->assertScript('document.querySelector(\'[dusk="inner"]\').style.display', ''); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Alpine/Transition/EntangleDeferComponent.php
legacy_tests/Browser/Alpine/Transition/EntangleDeferComponent.php
<?php namespace LegacyTests\Browser\Alpine\Transition; use Livewire\Component as BaseComponent; class EntangleDeferComponent extends BaseComponent { public $show = true; public $changeDom = false; public function render() { return <<<'EOD' <div> <div x-data="{ show: @entangle('show') }"> <button x-on:click="show = ! show" dusk="button">Alpine Toggle</button> <button wire:click="$toggle('show')" dusk="livewire-button">Livewire Toggle</button> <button wire:click="$toggle('changeDom')" dusk="change-dom">Change DOM</button> <div x-show="show" dusk="outer"> <div x-show.transition.duration.250ms="show" x-transition.duration.250ms dusk="inner"> <h1>@if ($changeDom) @json($show) @else static-filler @endif</h1> </div> </div> </div> </div> EOD; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SupportDateTimes/Test.php
legacy_tests/Browser/SupportDateTimes/Test.php
<?php namespace LegacyTests\Browser\SupportDateTimes; use Carbon\CarbonImmutable; use DateTime; use DateTimeImmutable; use Illuminate\Support\Carbon; use Livewire\Component; use Livewire\Livewire; use Tests\TestCase; class Test extends TestCase { public function test_date_support(): void { Livewire::test(new class extends Component { public $native; public $nativeImmutable; public $carbon; public $carbonImmutable; public $illuminate; public function mount() { $this->native = new DateTime('01/01/2001'); $this->nativeImmutable = new DateTimeImmutable('01/01/2001'); $this->carbon = \Carbon\Carbon::parse('01/01/2001'); $this->carbonImmutable = CarbonImmutable::parse('01/01/2001'); $this->illuminate = Carbon::parse('01/01/2001'); } public function addDay() { $this->native->modify('+1 day'); $this->nativeImmutable = $this->nativeImmutable->modify('+1 day'); $this->carbon->addDay(1); $this->carbonImmutable = $this->carbonImmutable->addDay(1); $this->illuminate->addDay(1); } public function render() { return <<<'HTML' <div> <span>native-{{ $native->format('m/d/Y') }}</span> <span>nativeImmutable-{{ $nativeImmutable->format('m/d/Y') }}</span> <span>carbon-{{ $carbon->format('m/d/Y') }}</span> <span>carbonImmutable-{{ $carbonImmutable->format('m/d/Y') }}</span> <span>illuminate-{{ $illuminate->format('m/d/Y') }}</span> </div> HTML; } }) ->assertSee('native-01/01/2001') ->assertSee('nativeImmutable-01/01/2001') ->assertSee('carbon-01/01/2001') ->assertSee('carbonImmutable-01/01/2001') ->assertSee('illuminate-01/01/2001') ->call('addDay') ->assertSee('native-01/02/2001') ->assertSee('nativeImmutable-01/02/2001') ->assertSee('carbon-01/02/2001') ->assertSee('carbonImmutable-01/02/2001') ->assertSee('illuminate-01/02/2001'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Replace/Test.php
legacy_tests/Browser/Replace/Test.php
<?php namespace LegacyTests\Browser\Replace; use Livewire\Component; use Livewire\Livewire; use Tests\BrowserTestCase; class Test extends BrowserTestCase { public function test_wire_replace() { Livewire::visit(new class extends Component { public $foo = false; public $bar = false; public $baz = false; public $bob = false; public $lob = false; public $quo = 0; public function render() { return <<<'HTML' <div> <button x-data="{ __foo: $wire.foo }" wire:click="$set('foo', true)" wire:replace dusk="foo"> <span dusk="foo.output" x-text="__foo === $wire.foo ? 'same' : 'different'">foo.output</span> </button> <button x-data="{ __bar: $wire.bar }" wire:click="$set('bar', true)" @if($bar) some-new-attribute="bar" @endif wire:replace dusk="bar"> <span dusk="bar.output" x-text="__bar === $wire.bar ? 'same' : 'different'">bar.output</span> </button> <button x-data="{ __baz: $wire.baz }" wire:click="$set('baz', true)" wire:replace.self dusk="baz"> <span dusk="baz.output" x-text="__baz === $wire.baz ? 'same' : 'different'">baz.output</span> </button> <button x-data="{ __bob: $wire.bob }" wire:click="$set('bob', true)" dusk="bob"> <span dusk="bob.output" x-text="__bob === $wire.bob ? 'same' : 'different'">bob.output</span> </button> <button x-data="{ __lob: $wire.lob }" wire:click="$set('lob', true)" dusk="lob"> <span dusk="lob.output" x-text="__lob === $wire.lob ? 'same' : 'different'">lob.output</span> </button> <button x-data="{ __quo: $wire.quo }" wire:click="$set('quo', $wire.quo + 1)" @if($quo === 1) wire:replace @elseif ($quo === 2) wire:replace.self @endif dusk="quo" > <span dusk="quo.output" x-text="__quo === $wire.quo ? 'same' : 'different'">quo.output</span> <span dusk="quo.output-diffed">{{ $quo }}</span> <span dusk="quo.output-ignored" wire:ignore>{{ $quo }}</span> </button> </div> HTML; } }) /** * wire:replace replaces children from update */ ->assertSeeIn('@foo.output', 'same') ->waitForLivewire()->click('@foo') ->assertSeeIn('@foo.output', 'different') ->tap(function ($b) { $this->assertSame( [true], $b->script("return document.querySelector('[dusk=\"foo\"]').__livewire_replace") ); }) /** * wire:replace merges attribute changes, but doesn't replace the element */ ->assertSeeIn('@bar.output', 'same') ->assertAttributeMissing('@bar', 'some-new-attribute') ->waitForLivewire()->click('@bar') ->assertSeeIn('@bar.output', 'different') ->assertAttribute('@bar', 'some-new-attribute', 'bar') /** * wire:replace.self replaces the element and all children */ ->assertSeeIn('@baz.output', 'same') ->waitForLivewire()->click('@baz') ->assertSeeIn('@baz.output', 'same') ->tap(function ($b) { // __livewire_replace_self is re-processed for the new element $this->assertSame( [true], $b->script("return document.querySelector('[dusk=\"baz\"]').__livewire_replace_self") ); }) /** * adding .__livewire_replace to element replaces children after update, but doesn't replace the element */ ->tap(function ($b) { $b->script("document.querySelector('[dusk=\"bob\"]').__livewire_replace = true"); }) ->assertSeeIn('@bob.output', 'same') ->waitForLivewire()->click('@bob') ->assertSeeIn('@bob.output', 'different') ->tap(function ($b) { // __livewire_replace hasn't been removed from the element because only the children were replaced $this->assertSame( [true], $b->script("return document.querySelector('[dusk=\"bob\"]').__livewire_replace") ); }) /** * adding .__livewire_replace_self to element replaces the element and all children */ ->tap(function ($b) { $b->script("document.querySelector('[dusk=\"lob\"]').__livewire_replace_self = true"); }) ->assertSeeIn('@lob.output', 'same') ->waitForLivewire()->click('@lob') ->assertSeeIn('@lob.output', 'same') ->tap(function ($b) { // __livewire_replace_self no longer exists because the element was replaced $this->assertSame( [null], $b->script("return document.querySelector('[dusk=\"lob\"]').__livewire_replace_self") ); }) /** * wire:replace replaces wire:ignored children */ ->assertSeeIn('@quo.output', 'same') ->assertSeeIn('@quo.output-diffed', '0') ->assertSeeIn('@quo.output-ignored', '0') ->assertAttributeMissing('@quo', 'wire:replace') ->assertAttributeMissing('@quo', 'wire:replace.self') ->waitForLivewire()->click('@quo') // there was no wire:replace - wire:ignore should be respected, dom diffed ->assertSeeIn('@quo.output', 'different') ->assertSeeIn('@quo.output-diffed', '1') ->assertSeeIn('@quo.output-ignored', '0') ->assertAttribute('@quo', 'wire:replace', '') // this update added wire:replace to the element ->assertAttributeMissing('@quo', 'wire:replace.self') ->waitForLivewire()->click('@quo') // We had wire:replace - wire:ignore should be overridden, but the element itself should not be replaced ->assertSeeIn('@quo.output', 'different') ->assertSeeIn('@quo.output-diffed', '2') ->assertSeeIn('@quo.output-ignored', '2') // this update added wire:replace.self to the element ->assertAttributeMissing('@quo', 'wire:replace') ->assertAttribute('@quo', 'wire:replace.self', '') ->waitForLivewire()->click('@quo') // We had wire:replace.self - everything should be overridden ->assertSeeIn('@quo.output', 'same') ->assertSeeIn('@quo.output-diffed', '3') ->assertSeeIn('@quo.output-ignored', '3') ->assertAttributeMissing('@quo', 'wire:replace') ->assertAttributeMissing('@quo', 'wire:replace.self') ->waitForLivewire()->click('@quo') // We no longer have wire:replace or wire:replace.self, we should return to DOM diffing and wire:ignore ->assertSeeIn('@quo.output', 'different') ->assertSeeIn('@quo.output-diffed', '4') ->assertSeeIn('@quo.output-ignored', '3') ->assertAttributeMissing('@quo', 'wire:replace') ->assertAttributeMissing('@quo', 'wire:replace.self') ; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/ComponentWithMount.php
legacy_tests/Browser/SyncHistory/ComponentWithMount.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class ComponentWithMount extends BaseComponent { public $renamedCompletely; public function mount($id) { $this->renamedCompletely = $id; } public function changeId() { $this->renamedCompletely = 5; } public function render() { return View::file(__DIR__.'/component-with-mount.blade.php'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/Step.php
legacy_tests/Browser/SyncHistory/Step.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Database\Eloquent\Model; class Step extends Model { use \Sushi\Sushi; protected $rows = [ [ 'id' => 1, 'title' => 'Step 1', ], [ 'id' => 2, 'title' => 'Step 2', ], [ 'id' => 3, 'title' => 'Step 3', ], ]; }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/Test.php
legacy_tests/Browser/SyncHistory/Test.php
<?php namespace LegacyTests\Browser\SyncHistory; use Laravel\Dusk\Browser; use LegacyTests\Browser\TestCase; use LegacyTests\Browser\DataBinding\Defer\Component as DeferComponent; class Test extends TestCase { function setUp(): void { parent::setUp(); $this->markTestSkipped(); // Removed this entire system in favor of SPA mode. // Leaving this test here in case we want to use these tests for SPA mode... } public function test_route_bound_properties_are_synced_with_browser_history() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history', ['step' => 1], false)) ->waitForText('Step 1 Active'); $browser->waitForLivewire()->click('@step-2') ->assertRouteIs('sync-history', ['step' => 2]); $browser ->back() ->assertRouteIs('sync-history', ['step' => 1]); }); } public function test_route_bound_properties_are_synced_with_browser_history_when_no_query_string_is_present() { $this->browse(function(Browser $browser) { $browser->visit(route('sync-history-without-query-string', [ 'step' => 1 ], false))->waitForText('Step 1 Active'); $browser->waitForLivewire()->click('@step-2')->assertRouteIs('sync-history-without-query-string', [ 'step' => 2 ]); $browser->back()->assertRouteIs('sync-history-without-query-string', [ 'step' => 1 ]); }); } public function test_that_query_bound_properties_are_synced_with_browser_history() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history', ['step' => 1], false)) ->waitForText('Help is currently disabled') ->assertQueryStringHas('showHelp', 'false'); $browser->waitForLivewire()->click('@toggle-help') ->assertQueryStringHas('showHelp', 'true'); $browser->waitForLivewire()->click('@toggle-help') ->waitForText('Help is currently disabled') ->assertQueryStringHas('showHelp', 'false'); $browser->back() ->waitForText('Help is currently enabled') ->assertQueryStringHas('showHelp', 'true'); $browser->back() ->waitForText('Help is currently disabled') ->assertQueryStringHas('showHelp', 'false'); }); } public function test_that_route_and_query_bound_properties_can_both_be_synced_with_browser_history() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history', ['step' => 1], false)) ->waitForText('Step 1 Active') ->waitForText('Help is currently disabled') ->assertQueryStringHas('showHelp', 'false'); $browser->waitForLivewire()->click('@toggle-help') ->assertQueryStringHas('showHelp', 'true'); $browser->waitForLivewire()->click('@step-2') ->assertRouteIs('sync-history', ['step' => 2]) ->assertQueryStringHas('showHelp', 'true'); $browser->waitForLivewire()->click('@toggle-help') ->assertQueryStringHas('showHelp', 'false'); $browser->back() ->waitForText('Help is currently enabled') ->assertQueryStringHas('showHelp', 'true') ->assertRouteIs('sync-history', ['step' => 2]); $browser->back() ->waitForText('Step 1 Active') ->assertRouteIs('sync-history', ['step' => 1]) ->assertQueryStringHas('showHelp', 'true'); $browser->back() ->waitForText('Help is currently disabled') ->assertQueryStringHas('showHelp', 'false'); }); } public function test_that_query_updates_from_child_components_can_coexist() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history', ['step' => 1], false)) ->waitForText('Step 1 Active') ->waitForText('Dark mode is currently disabled') ->assertQueryStringHas('darkmode', 'false'); $browser->waitForLivewire()->click('@toggle-darkmode') ->assertQueryStringHas('darkmode', 'true'); $browser->waitForLivewire()->click('@step-2') ->assertRouteIs('sync-history', ['step' => 2]) ->assertQueryStringHas('darkmode', 'true'); $browser->waitForLivewire()->click('@toggle-darkmode') ->assertQueryStringHas('darkmode', 'false'); $browser->back() ->waitForText('Dark mode is currently enabled') ->assertQueryStringHas('darkmode', 'true') ->assertRouteIs('sync-history', ['step' => 2]); $browser->back() ->waitForText('Step 1 Active') ->assertRouteIs('sync-history', ['step' => 1]) ->assertQueryStringHas('darkmode', 'true'); $browser->back() ->assertRouteIs('sync-history', ['step' => 1]) ->waitForText('Dark mode is currently disabled') ->assertQueryStringHas('darkmode', 'false'); }); } public function test_that_if_a_parameter_comes_in_from_the_route_and_doesnt_have_a_matching_property_things_dont_break() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history-without-mount', ['id' => 1], false)) ->assertSeeIn('@output', '1') ->waitForLivewire()->click('@button') ->assertSeeIn('@output', '5'); }); } public function test_that_we_are_not_leaking_old_components_into_history_state_on_refresh() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history', ['step' => 1], false)) ->assertScript('Object.keys(window.history.state.livewire).length', 2) ->refresh() ->assertScript('Object.keys(window.history.state.livewire).length', 2); }); } public function test_that_livewire_does_not_overwrite_existing_history_state() { $this->browse(function (Browser $browser) { $browser->visit(route('sync-history', ['step' => 1], false)) ->script('window.history.pushState({ ...window.history.state, userHistoryState: { foo: "bar" }}, document.title)'); $browser->refresh() ->assertScript('Object.keys(window.history.state.userHistoryState).length', 1); }); } public function test_that_we_are_not_setting_history_state_unless_there_are_route_bound_params_or_query_string_properties() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, DeferComponent::class) ->assertScript('history.state', null) ; }); } public function test_that_changing_a_radio_multiple_times_and_hitting_back_multiple_times_works() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, SingleRadioComponent::class) ->waitForLivewire()->radio('@foo.bar', 'bar') ->assertRadioSelected('@foo.bar', 'bar') ->assertQueryStringHas('foo', 'bar') ->waitForLivewire()->radio('@foo.baz', 'baz') ->assertRadioSelected('@foo.baz', 'baz') ->assertRadioNotSelected('@foo.bar', 'bar') ->assertQueryStringHas('foo', 'baz') ->waitForLivewire()->radio('@foo.bar', 'bar') ->assertRadioSelected('@foo.bar', 'bar') ->assertQueryStringHas('foo', 'bar') ->back() ->assertRadioSelected('@foo.baz', 'baz') ->assertRadioNotSelected('@foo.bar', 'bar') ->assertQueryStringHas('foo', 'baz') ->back() ->assertRadioSelected('@foo.bar', 'bar') ->assertRadioNotSelected('@foo.baz', 'baz') ->assertQueryStringHas('foo', 'bar') ->back() ->assertRadioNotSelected('@foo.baz', 'baz') ->assertRadioNotSelected('@foo.bar', 'bar') ->assertQueryStringMissing('foo') ; }); } public function test_that_alpine_watchers_used_by_entangle_are_fired_when_back_button_is_hit() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, ComponentWithAlpineEntangle::class) ->assertSeeIn('@blade.output', '1') ->assertSeeIn('@alpine.output', 'bar') ->waitForLivewire()->click('@next') ->assertSeeIn('@blade.output', '2') ->waitForLivewire()->click('@changeFoo') ->assertSeeIn('@alpine.output', 'baz') ->back() ->assertSeeIn('@blade.output', '1') ->assertSeeIn('@alpine.output', 'bar') ; }); } public function test_optional_route_bound_properties_are_synced_with_browser_history() { $this->browse(function(Browser $browser) { $browser->visit(route('sync-history-with-optional-parameter', [], false)) ->waitForText('Activate Step 1') ->waitForLivewire() ->click('@step-1') ->assertRouteIs('sync-history-with-optional-parameter', [ 'step' => 1 ]) ->back() ->assertRouteIs('sync-history-with-optional-parameter', []); }); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/ComponentWithAlpineEntangle.php
legacy_tests/Browser/SyncHistory/ComponentWithAlpineEntangle.php
<?php namespace LegacyTests\Browser\SyncHistory; use Livewire\Component; class ComponentWithAlpineEntangle extends Component { public $page = 1; public $foo = 'bar'; protected $queryString = ['page']; public function nextPage() { $this->page++; } public function render() { return <<<'blade' <div> <button wire:click="nextPage" dusk="next">next page</button> <span dusk="blade.output">{{ $page }}</span> <button wire:click="$set('foo', 'baz')" dusk="changeFoo">prev page</button> <div x-data="{ foo: @entangle('foo') }" x-text="foo" dusk="alpine.output"></div> </div> blade; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/SingleRadioComponent.php
legacy_tests/Browser/SyncHistory/SingleRadioComponent.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class SingleRadioComponent extends BaseComponent { public $foo; protected $queryString = ['foo']; public function render() { return View::file(__DIR__.'/single-radio-component.blade.php'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/single-radio-component.blade.php
legacy_tests/Browser/SyncHistory/single-radio-component.blade.php
<div> <input dusk="foo.bar" type="radio" wire:model="foo" value="bar" name="foo"> <input dusk="foo.baz" type="radio" wire:model="foo" value="baz" name="foo"> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/view-without-subcomponent.blade.php
legacy_tests/Browser/SyncHistory/view-without-subcomponent.blade.php
<div> <dl> <dt>Component ID</dt> <dd>{{ $id }}</dd> @foreach (Tests\Browser\SyncHistory\Step::all() as $each_step) <dt>{{ $each_step->title }}</dt> <dd> @if($each_step->is($step)) <button disabled dusk="step-{{ $each_step->id }}" wire:click="setStep({{ $each_step->id }})" > Step {{ $each_step->title }} Active </button> @else <button dusk="step-{{ $each_step->id }}" wire:click="setStep({{ $each_step->id }})" > Activate {{ $each_step->title }} </button> @endif </dd> @endforeach </dl> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/child.blade.php
legacy_tests/Browser/SyncHistory/child.blade.php
<div> <hr /> <dt>DarkMode</dt> <dd> Dark mode is currently {{ $darkmode ? 'enabled' : 'disabled' }}. <button dusk="toggle-darkmode" wire:click="toggleDarkmode">Toggle</button> </dd> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/ChildComponent.php
legacy_tests/Browser/SyncHistory/ChildComponent.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class ChildComponent extends BaseComponent { public $darkmode = false; protected $queryString = ['darkmode']; public function toggleDarkmode() { $this->darkmode = ! $this->darkmode; } public function render() { return View::file(__DIR__.'/child.blade.php')->with(['id' => $this->id]); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/ComponentWithoutQueryString.php
legacy_tests/Browser/SyncHistory/ComponentWithoutQueryString.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class ComponentWithoutQueryString extends BaseComponent { public $step; public function mount(Step $step) { $this->step = $step; } public function setStep($id) { $this->step = Step::findOrFail($id); } public function render() { return View::file(__DIR__.'/view-without-subcomponent.blade.php')->with([ 'id' => $this->id]); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/component-with-mount.blade.php
legacy_tests/Browser/SyncHistory/component-with-mount.blade.php
<div> <span dusk="output">{{ $renamedCompletely }}</span> <button wire:click="changeId" dusk="button">Change ID</button> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/ComponentWithOptionalParameter.php
legacy_tests/Browser/SyncHistory/ComponentWithOptionalParameter.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class ComponentWithOptionalParameter extends BaseComponent { public $step; public function mount(Step $step) { $this->step = $step; } public function setStep($id) { $this->step = Step::findOrFail($id); } public function render() { return View::file(__DIR__.'/view-without-subcomponent.blade.php')->with([ 'id' => $this->id]); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/view.blade.php
legacy_tests/Browser/SyncHistory/view.blade.php
<div> <dl> <dt>Component ID</dt> <dd>{{ $id }}</dd> @foreach (Tests\Browser\SyncHistory\Step::all() as $each_step) <dt>{{ $each_step->title }}</dt> <dd> @if($each_step->is($step)) <button disabled dusk="step-{{ $each_step->id }}" wire:click="setStep({{ $each_step->id }})" > Step {{ $each_step->title }} Active </button> @else <button dusk="step-{{ $each_step->id }}" wire:click="setStep({{ $each_step->id }})" > Activate {{ $each_step->title }} </button> @endif </dd> @endforeach <dt>Help</dt> <dd> Help is currently {{ $showHelp ? 'enabled' : 'disabled' }}. <button dusk="toggle-help" wire:click="toggleHelp">Toggle</button> </dd> @livewire(\Tests\Browser\SyncHistory\ChildComponent::class) </dl> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/SyncHistory/Component.php
legacy_tests/Browser/SyncHistory/Component.php
<?php namespace LegacyTests\Browser\SyncHistory; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class Component extends BaseComponent { public $step; public $showHelp = false; protected $queryString = ['showHelp']; public function mount(Step $step) { $this->step = $step; } public function setStep($id) { $this->step = Step::findOrFail($id); } public function toggleHelp() { $this->showHelp = ! $this->showHelp; } public function render() { return View::file(__DIR__.'/view.blade.php')->with(['id' => $this->id]); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Offline/Test.php
legacy_tests/Browser/Offline/Test.php
<?php namespace LegacyTests\Browser\Offline; use Livewire\Component; use Livewire\Livewire; use Tests\BrowserTestCase; class Test extends BrowserTestCase { public function test_wire_offline() { Livewire::visit(new class extends Component { public function render() { return <<<'HTML' <div> <span wire:offline dusk="whileOffline">Offline</span> <span wire:offline.class="foo" dusk="addClass"></span> <span class="hidden" wire:offline.class.remove="hidden" dusk="removeClass"></span> <span wire:offline.attr="disabled" dusk="withAttribute"></span> <span wire:offline.attr.remove="disabled" disabled="true" dusk="withoutAttribute"></span> </div> HTML; } }) ->assertMissing('@whileOffline') ->offline() ->assertSeeIn('@whileOffline', 'Offline') ->online() ->assertMissing('@whileOffline') /** * add element class while offline */ ->online() ->assertClassMissing('@addClass', 'foo') ->offline() ->assertHasClass('@addClass', 'foo') /** * add element class while offline */ ->online() ->assertHasClass('@removeClass', 'hidden') ->offline() ->assertClassMissing('@removeClass', 'hidden') /** * add element attribute while offline */ ->online() ->assertAttributeMissing('@withAttribute', 'disabled') ->offline() ->assertAttribute('@withAttribute', 'disabled', 'true') /** * remove element attribute while offline */ ->online() ->assertAttribute('@withoutAttribute', 'disabled', 'true') ->offline() ->assertAttributeMissing('@withoutAttribute', 'disabled') ; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Extensions/Test.php
legacy_tests/Browser/Extensions/Test.php
<?php namespace LegacyTests\Browser\Extensions; use Laravel\Dusk\Browser; use Livewire\Component; use Livewire\Livewire; use Tests\BrowserTestCase; class Test extends BrowserTestCase { public function test_custom_wire_directive(): void { Livewire::visit(new class extends Component { public $count = 0; public function render() { $this->count++; return <<<'HTML' <div> <button wire:click="$refresh" dusk="refresh">refresh</button> @if ($count > 1) <button wire:foo>foo</button> @endif </div> HTML; } }) ->tap(fn(Browser $browser) => $browser->script([ 'window.renameMe = false', "window.Livewire.directive('foo', ({ el, directive, component }) => { window.renameMe = true })", ])) ->assertScript('window.renameMe', false) ->waitForLivewire()->click('@refresh') ->assertScript('window.renameMe', true) ; } public function test_custom_wire_directive_doesnt_register_wildcard_event_listener(): void { Livewire::visit(new class extends Component { public $count = 0; public function inc() { $this->count++; } public function render() { return <<<'HTML' <div> <span dusk="target">{{ $count }}</span> <div wire:foo="inc"> <button x-on:click="$dispatch('foo')" wire:click="inc" type="button" dusk="button">foo</button> </div> <script> document.addEventListener('DOMContentLoaded', () => { window.Livewire.directive('foo', ({ el, directive, component }) => { // By registering this directive, we should be preventing Livewire // from registering an event listener for the "foo" event... }) }) </script> </div> HTML; } }) ->assertSeeIn('@target', '0') ->waitForLivewire()->click('@button') ->assertSeeIn('@target', '1') ; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/Test.php
legacy_tests/Browser/Events/Test.php
<?php namespace LegacyTests\Browser\Events; use LegacyTests\Browser\TestCase; class Test extends TestCase { public function test() { $this->browse(function ($browser) { $this->visitLivewireComponent($browser, [Component::class, 'component-a' => NestedComponentA::class, 'component-b' => NestedComponentB::class]) /** * receive event from global fire */ ->waitForLivewire()->tap(function ($browser) { $browser->script('window.Livewire.dispatch("foo", { value: "bar" })'); }) ->waitUsing(5, 75, function () use ($browser) { return $browser->assertSeeIn('@lastEventForParent', 'bar') ->assertSeeIn('@lastEventForChildA', 'bar') ->assertSeeIn('@lastEventForChildB', 'bar'); }) /** * receive event from action fire */ ->waitForLivewire()->click('@dispatch.baz') ->waitUsing(5, 75, function () use ($browser) { return $browser->assertSeeIn('@lastEventForParent', 'baz') ->assertSeeIn('@lastEventForChildA', 'baz') ->assertSeeIn('@lastEventForChildB', 'baz'); }) /** * receive event from component fire, and make sure global listener receives event too */ ->tap(function ($b) { $b->script([ "window.lastFooEventValue = ''", "window.Livewire.on('foo', ({ value }) => { lastFooEventValue = value })", ]);}) ->waitForLivewire()->click('@dispatch.bob') ->waitUsing(5, 75, function () use ($browser) { return $browser->assertScript('window.lastFooEventValue', 'bob'); }) /** * receive event from action fired only to ancestors, and make sure global listener doesnt receive it */ ->waitForLivewire()->click('@dispatch.law') ->waitUsing(5, 75, function () use ($browser) { return $browser->assertSeeIn('@lastEventForParent', 'law') ->assertSeeIn('@lastEventForChildA', 'bob') ->assertSeeIn('@lastEventForChildB', 'bob') ->assertScript('window.lastFooEventValue', 'bob'); }) /** * receive event from action fired only to component name, and make sure global listener doesnt receive it */ ->waitForLivewire()->click('@dispatch.blog') ->waitUsing(5, 75, function () use ($browser) { return $browser->assertSeeIn('@lastEventForParent', 'law') ->assertSeeIn('@lastEventForChildA', 'bob') ->assertSeeIn('@lastEventForChildB', 'blog') ->assertScript('window.lastFooEventValue', 'bob'); }) ; }); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/NestedComponentA.php
legacy_tests/Browser/Events/NestedComponentA.php
<?php namespace LegacyTests\Browser\Events; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class NestedComponentA extends BaseComponent { protected $listeners = ['foo']; public $lastEvent = ''; public function foo($value) { $this->lastEvent = $value; } public function render() { return View::file(__DIR__.'/nested-a.blade.php'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/nested-b.blade.php
legacy_tests/Browser/Events/nested-b.blade.php
<div> <span dusk="lastEventForChildB">{{ $this->lastEvent }}</span> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/NestedComponentB.php
legacy_tests/Browser/Events/NestedComponentB.php
<?php namespace LegacyTests\Browser\Events; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class NestedComponentB extends BaseComponent { protected $listeners = ['foo']; public $lastEvent = ''; public function foo($value) { $this->lastEvent = $value; } public function render() { return View::file(__DIR__.'/nested-b.blade.php'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/nested-a.blade.php
legacy_tests/Browser/Events/nested-a.blade.php
<div id="nested-root-a"> <span dusk="lastEventForChildA">{{ $this->lastEvent }}</span> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/view.blade.php
legacy_tests/Browser/Events/view.blade.php
<div> <span dusk="lastEventForParent">{{ $this->lastEvent }}</span> <button wire:click="$dispatch('foo', { value: 'baz' })" dusk="dispatch.baz"></button> <button wire:click="$dispatch('foo', { value: 'bob' })" dusk="dispatch.bob"></button> <button wire:click="$dispatchSelf('foo', { value: 'law' })" dusk="dispatch.law"></button> <button wire:click="$dispatchTo('component-b', 'foo', { value: 'blog' })" dusk="dispatch.blog"></button> @livewire(LegacyTests\Browser\Events\NestedComponentA::class) @livewire(LegacyTests\Browser\Events\NestedComponentB::class) </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Events/Component.php
legacy_tests/Browser/Events/Component.php
<?php namespace LegacyTests\Browser\Events; use Illuminate\Support\Facades\View; use Livewire\Component as BaseComponent; class Component extends BaseComponent { protected $listeners = ['foo']; public $lastEvent = ''; public function foo($value) { $this->lastEvent = $value; } public function render() { return View::file(__DIR__.'/view.blade.php'); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Browser/Init/Test.php
legacy_tests/Browser/Init/Test.php
<?php namespace LegacyTests\Browser\Init; use Livewire\Component; use Livewire\Livewire; use Tests\BrowserTestCase; class Test extends BrowserTestCase { public function test_wire_init(): void { Livewire::visit(new class extends Component { public $output = ''; public function setOutputToFoo() { $this->output = 'foo'; } public function render() { return <<<'HTML' <div wire:init="setOutputToFoo"> <span dusk="output">{{ $output }}</span> </div> HTML; } }) /** * wire:init runs on page load. */ ->waitForText('foo') ->assertSee('foo') ; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/TestCase.php
legacy_tests/Unit/TestCase.php
<?php namespace LegacyTests\Unit; use Orchestra\Testbench\TestCase as BaseTestCase; use Livewire\LivewireServiceProvider; use Livewire\Livewire; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Artisan; class TestCase extends BaseTestCase { public function setUp(): void { $this->afterApplicationCreated(function () { $this->makeACleanSlate(); }); $this->beforeApplicationDestroyed(function () { $this->makeACleanSlate(); }); parent::setUp(); } public function makeACleanSlate() { Artisan::call('view:clear'); app()->forgetInstance('livewire.factory'); File::deleteDirectory($this->livewireViewsPath()); File::deleteDirectory($this->livewireClassesPath()); File::deleteDirectory($this->livewireTestsPath()); File::delete(app()->bootstrapPath('cache/livewire-components.php')); } protected function getPackageProviders($app) { return [ LivewireServiceProvider::class, ]; } protected function getEnvironmentSetUp($app) { $app['config']->set('view.paths', [ __DIR__.'/views', resource_path('views'), ]); $app['config']->set('app.key', 'base64:Hupx3yAySikrM2/edkZQNQHslgDWYfiBfCuSThJ5SK8='); $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ]); $app['config']->set('filesystems.disks.unit-downloads', [ 'driver' => 'local', 'root' => __DIR__.'/fixtures', ]); } protected function resolveApplicationHttpKernel($app) { $app->singleton('Illuminate\Contracts\Http\Kernel', 'LegacyTests\HttpKernel'); } protected function livewireClassesPath($path = '') { return app_path('Livewire'.($path ? '/'.$path : '')); } protected function livewireViewsPath($path = '') { return resource_path('views').'/livewire'.($path ? '/'.$path : ''); } protected function livewireTestsPath($path = '') { return base_path('tests/Feature/Livewire'.($path ? '/'.$path : '')); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-session-flash.blade.php
legacy_tests/Unit/views/show-session-flash.blade.php
<div> @if (session('status')) <div class="alert-success mb-" role="alert"> {{ session('status') }} </div> @endif </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-children.blade.php
legacy_tests/Unit/views/show-children.blade.php
<div> @foreach ($children as $child) @livewire('child', ['name' => $child], key($child)) @endforeach </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/dump-errors.blade.php
legacy_tests/Unit/views/dump-errors.blade.php
<div> @json($errors->toArray()) @error('test') @enderror @component('dump-errors-nested-component')@endcomponent </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/model-arrow-title-view.blade.php
legacy_tests/Unit/views/model-arrow-title-view.blade.php
<div> @if ($model) {{ $this->model->title }} @endif </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/isset-foo-bar.blade.php
legacy_tests/Unit/views/isset-foo-bar.blade.php
<div> {{ var_dump(isset($this->foo_bar)) }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/var-dump-foo-bar.blade.php
legacy_tests/Unit/views/var-dump-foo-bar.blade.php
<div> {{ var_dump($this->foo_bar) }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/null-view.blade.php
legacy_tests/Unit/views/null-view.blade.php
<div></div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/execute-callback.blade.php
legacy_tests/Unit/views/execute-callback.blade.php
<div> <?php $callback(); ?> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-html.blade.php
legacy_tests/Unit/views/show-html.blade.php
<div><p style="display: none">Hello HTML</p></div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/this-keyword.blade.php
legacy_tests/Unit/views/this-keyword.blade.php
<div> {{ get_class($this) }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/var-dump-foo.blade.php
legacy_tests/Unit/views/var-dump-foo.blade.php
<div> {{ var_dump($this->foo) }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/isset-foo.blade.php
legacy_tests/Unit/views/isset-foo.blade.php
<div> {{ var_dump(isset($this->foo)) }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/assets-directive.blade.php
legacy_tests/Unit/views/assets-directive.blade.php
@livewireStyles @livewireScripts($options)
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/file-download-component.blade.php
legacy_tests/Unit/views/file-download-component.blade.php
<div> @if($downloaded) Thanks! @endif </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/fillable-view.blade.php
legacy_tests/Unit/views/fillable-view.blade.php
<div> {{ $publicProperty }} {{ $protectedProperty }} {{ $privateProperty }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-property-value.blade.php
legacy_tests/Unit/views/show-property-value.blade.php
<span>{{ $message }}</span>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/entangle.blade.php
legacy_tests/Unit/views/entangle.blade.php
<x-input wire:model.defer="foo"/> <x-input wire:model="bar"/>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/wireables.blade.php
legacy_tests/Unit/views/wireables.blade.php
<div> <div> @if ($wireable) {{ $wireable->message }} @if ($wireable->embeddedWireable ?? false) {{ $wireable->embeddedWireable->message }} @endif @endif </div> </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/load-balancer-parent.blade.php
legacy_tests/Unit/views/load-balancer-parent.blade.php
<div> Parent @livewire('child', ['number' => 1]) @livewire('child', ['number' => 2]) </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-name.blade.php
legacy_tests/Unit/views/show-name.blade.php
<!-- Test comment <div>Commented out code</div> --> <span>{{ $name ?? '' }}</span>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/attribute-bag-macros.blade.php
legacy_tests/Unit/views/attribute-bag-macros.blade.php
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-child.blade.php
legacy_tests/Unit/views/show-child.blade.php
<div> @livewire('child', $child) </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/foreach-models-arrow-title-view.blade.php
legacy_tests/Unit/views/foreach-models-arrow-title-view.blade.php
<div> @foreach ($models as $model) {{ $model->title }} @endforeach </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/show-name-with-this.blade.php
legacy_tests/Unit/views/show-name-with-this.blade.php
<span>{{ $this->name }}</span>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/dump-errors-nested-component.blade.php
legacy_tests/Unit/views/dump-errors-nested-component.blade.php
<div> @if (isset($errors) && $errors->has('bar')) sharedError:{{ $errors->first('bar') }} @endif </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/load-balancer-child.blade.php
legacy_tests/Unit/views/load-balancer-child.blade.php
<div> child-content-{{ $number }} </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/render-component.blade.php
legacy_tests/Unit/views/render-component.blade.php
<div> @isset($params) @livewire($component, $params) @else @livewire($component) @endisset </div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/rootless-view.blade.php
legacy_tests/Unit/views/rootless-view.blade.php
This all you got?!
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/components/input.blade.php
legacy_tests/Unit/views/components/input.blade.php
<div x-data="{ foo: @entangle($attributes->wire('model')) }"></div>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-extends.blade.php
legacy_tests/Unit/views/layouts/app-extends.blade.php
@yield('content') {{ $bar }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/data-test.blade.php
legacy_tests/Unit/views/layouts/data-test.blade.php
{{ $title }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-custom-slot.blade.php
legacy_tests/Unit/views/layouts/app-custom-slot.blade.php
{{ $main }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-anonymous-component.blade.php
legacy_tests/Unit/views/layouts/app-anonymous-component.blade.php
@props([ 'foo' => 'bar', ]) <div {{ $attributes->merge(['id' => 'foo']) }}> {{ $foo }} </div> {{ $slot }} @isset($bar) {{ $bar }} @endisset
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-anonymous-component-with-required-prop.blade.php
legacy_tests/Unit/views/layouts/app-anonymous-component-with-required-prop.blade.php
@props([ 'foo' => 'bar', 'bar', ]) <div {{$attributes}}> {{ $foo }} </div> {{ $slot }} {{ $bar }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-with-bar.blade.php
legacy_tests/Unit/views/layouts/app-with-bar.blade.php
{{ $bar }} {{ $slot }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-custom-section.blade.php
legacy_tests/Unit/views/layouts/app-custom-section.blade.php
@yield('body')
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-from-class-component.blade.php
legacy_tests/Unit/views/layouts/app-from-class-component.blade.php
@yield('content') {{ $slot }} <div {{ $attributes->merge(['id' => 'foo']) }}> {{ $foo }} </div> @isset($bar) {{ $bar }} @endisset
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app-with-baz-hardcoded.blade.php
legacy_tests/Unit/views/layouts/app-with-baz-hardcoded.blade.php
baz {{ $slot }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/legacy_tests/Unit/views/layouts/app.blade.php
legacy_tests/Unit/views/layouts/app.blade.php
@yield('content') {{ $slot }}{{ $customParam ?? '' }}
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/LivewireServiceProvider.php
src/LivewireServiceProvider.php
<?php namespace Livewire; use Livewire\Finder\Finder; use Livewire\Factory\Factory; use Livewire\Compiler\Compiler; use Illuminate\Foundation\Console\AboutCommand; use Composer\InstalledVersions; use Livewire\Compiler\CacheManager; class LivewireServiceProvider extends \Illuminate\Support\ServiceProvider { public function register() { $this->registerLivewireServices(); $this->registerConfig(); $this->bootEventBus(); $this->registerMechanisms(); } public function boot() { $this->bootConfig(); $this->bootMechanisms(); $this->bootFeatures(); } protected function registerLivewireServices() { $this->app->alias(LivewireManager::class, 'livewire'); $this->app->singleton(LivewireManager::class); app('livewire')->setProvider($this); $this->app->singleton('livewire.finder', function () { $finder = new Finder; $finder->addLocation(classNamespace: config('livewire.class_namespace')); $finder->addLocation(viewPath: config('livewire.component_path')); return $finder; }); $this->app->singleton('livewire.compiler', function () { return new Compiler( new CacheManager( storage_path('framework/views/livewire') ) ); }); $this->app->scoped('livewire.factory', function ($app) { return new Factory( $app['livewire.finder'], $app['livewire.compiler'] ); }); } protected function registerConfig() { $config = __DIR__.'/../config/livewire.php'; $this->publishes([$config => base_path('config/livewire.php')], ['livewire', 'livewire:config']); $this->mergeConfigFrom($config, 'livewire'); } protected function bootEventBus() { app(EventBus::class)->boot(); } protected function getMechanisms() { return [ Mechanisms\PersistentMiddleware\PersistentMiddleware::class, Mechanisms\HandleComponents\HandleComponents::class, Mechanisms\HandleRequests\HandleRequests::class, Mechanisms\FrontendAssets\FrontendAssets::class, Mechanisms\ExtendBlade\ExtendBlade::class, Mechanisms\CompileLivewireTags\CompileLivewireTags::class, Mechanisms\ClearCachedFiles::class, Mechanisms\RenderComponent::class, Mechanisms\DataStore::class, ]; } protected function registerMechanisms() { foreach ($this->getMechanisms() as $mechanism) { app($mechanism)->register(); } } protected function bootConfig() { // Adapt v4 config to v3 config... config()->set( 'livewire.component_locations', config('livewire.component_locations', [ resource_path('views/components'), resource_path('views/livewire'), ]) ); config()->set( 'livewire.component_layout', config('livewire.component_layout', config('livewire.layout', null)) ); config()->set( 'livewire.component_placeholder', config('livewire.component_placeholder', config('livewire.lazy_placeholder', null)) ); config()->set( 'livewire.make_command', config('livewire.make_command', [ 'type' => 'class', 'emoji' => false, ]) ); // Register view-based component locations and namespaces... foreach (config('livewire.component_locations', []) as $location) { app('livewire.finder')->addLocation(viewPath: $location); if (! is_dir($location)) continue; app('blade.compiler')->anonymousComponentPath($location); app('view')->addLocation($location); } foreach (config('livewire.component_namespaces', []) as $namespace => $location) { app('livewire.finder')->addNamespace($namespace, viewPath: $location); if (! is_dir($location)) continue; app('blade.compiler')->anonymousComponentPath($location, $namespace); app('view')->addNamespace($namespace, $location); } } protected function bootMechanisms() { if (class_exists(AboutCommand::class) && class_exists(InstalledVersions::class)) { AboutCommand::add('Livewire', [ 'Livewire' => InstalledVersions::getPrettyVersion('livewire/livewire'), ]); } foreach ($this->getMechanisms() as $mechanism) { app($mechanism)->boot(); } } protected function bootFeatures() { foreach([ Features\SupportWireModelingNestedComponents\SupportWireModelingNestedComponents::class, Features\SupportMultipleRootElementDetection\SupportMultipleRootElementDetection::class, Features\SupportMorphAwareBladeCompilation\SupportMorphAwareBladeCompilation::class, Features\SupportDisablingBackButtonCache\SupportDisablingBackButtonCache::class, Features\SupportNestedComponentListeners\SupportNestedComponentListeners::class, Features\SupportHtmlAttributeForwarding\SupportHtmlAttributeForwarding::class, Features\SupportAutoInjectedAssets\SupportAutoInjectedAssets::class, Features\SupportComputed\SupportLegacyComputedPropertySyntax::class, Features\SupportNestingComponents\SupportNestingComponents::class, Features\SupportCompiledWireKeys\SupportCompiledWireKeys::class, Features\SupportScriptsAndAssets\SupportScriptsAndAssets::class, Features\SupportBladeAttributes\SupportBladeAttributes::class, Features\SupportConsoleCommands\SupportConsoleCommands::class, Features\SupportPageComponents\SupportPageComponents::class, Features\SupportReactiveProps\SupportReactiveProps::class, Features\SupportReleaseTokens\SupportReleaseTokens::class, Features\SupportFileDownloads\SupportFileDownloads::class, Features\SupportJsEvaluation\SupportJsEvaluation::class, Features\SupportMagicActions\SupportMagicActions::class, Features\SupportQueryString\SupportQueryString::class, Features\SupportFileUploads\SupportFileUploads::class, Features\SupportTeleporting\SupportTeleporting::class, Features\SupportLazyLoading\SupportLazyLoading::class, Features\SupportFormObjects\SupportFormObjects::class, Features\SupportAttributes\SupportAttributes::class, Features\SupportPagination\SupportPagination::class, Features\SupportValidation\SupportValidation::class, Features\SupportWithMethod\SupportWithMethod::class, Features\SupportIsolating\SupportIsolating::class, Features\SupportRedirects\SupportRedirects::class, Features\SupportStreaming\SupportStreaming::class, Features\SupportJsModules\SupportJsModules::class, Features\SupportNavigate\SupportNavigate::class, Features\SupportEntangle\SupportEntangle::class, Features\SupportWireRef\SupportWireRef::class, Features\SupportRouting\SupportRouting::class, Features\SupportLocales\SupportLocales::class, Features\SupportTesting\SupportTesting::class, Features\SupportIslands\SupportIslands::class, Features\SupportModels\SupportModels::class, Features\SupportEvents\SupportEvents::class, Features\SupportSlots\SupportSlots::class, Features\SupportJson\SupportJson::class, // Some features we want to have priority over others... Features\SupportLifecycleHooks\SupportLifecycleHooks::class, Features\SupportLegacyModels\SupportLegacyModels::class, Features\SupportWireables\SupportWireables::class, ] as $feature) { app('livewire')->componentHook($feature); } ComponentHookRegistry::boot(); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/ComponentHookRegistry.php
src/ComponentHookRegistry.php
<?php namespace Livewire; use WeakMap; use Livewire\Drawer\Utils; class ComponentHookRegistry { protected static $components; protected static $componentHooks = []; static function register($hook) { if (method_exists($hook, 'provide')) $hook::provide(); if (in_array($hook, static::$componentHooks)) return; static::$componentHooks[] = $hook; } static function getHook($component, $hook) { if (! isset(static::$components[$component])) return; $componentHooks = static::$components[$component]; foreach ($componentHooks as $componentHook) { if ($componentHook instanceof $hook) return $componentHook; } } static function boot() { static::$components = new WeakMap; foreach (static::$componentHooks as $hook) { on('mount', function ($component, $params, $key, $parent, $attributes) use ($hook) { if (! $hook = static::initializeHook($hook, $component)) { return; } $hook->callBoot(); $hook->callMount($params, $parent, $attributes); }); on('hydrate', function ($component, $memo) use ($hook) { if (! $hook = static::initializeHook($hook, $component)) { return; } $hook->callBoot(); $hook->callHydrate($memo); }); } on('update', function ($component, $fullPath, $newValue) { $propertyName = Utils::beforeFirstDot($fullPath); return static::proxyCallToHooks($component, 'callUpdate')($propertyName, $fullPath, $newValue); }); on('call', function ($component, $method, $params, $componentContext, $earlyReturn, $metadata) { return static::proxyCallToHooks($component, 'callCall')($method, $params, $earlyReturn, $metadata, $componentContext); }); on('render', function ($component, $view, $data) { return static::proxyCallToHooks($component, 'callRender')($view, $data); }); on('renderIsland', function ($component, $name, $view, $data) { return static::proxyCallToHooks($component, 'callRenderIsland')($name, $view, $data); }); on('dehydrate', function ($component, $context) { static::proxyCallToHooks($component, 'callDehydrate')($context); }); on('destroy', function ($component, $context) { static::proxyCallToHooks($component, 'callDestroy')($context); }); on('exception', function ($target, $e, $stopPropagation) { if ($target instanceof \Livewire\Component) { static::proxyCallToHooks($target, 'callException')($e, $stopPropagation); } }); } static public function initializeHook($hook, $target) { if (! isset(static::$components[$target])) static::$components[$target] = []; $hook = new $hook; $hook->setComponent($target); // If no `skip` method has been implemented, then boot the hook anyway if (method_exists($hook, 'skip') && $hook->skip()) { return; } static::$components[$target][] = $hook; return $hook; } static function proxyCallToHooks($target, $method) { return function (...$params) use ($target, $method) { $forwardCallbacks = []; foreach (static::$components[$target] ?? [] as $hook) { if ($callback = $hook->{$method}(...$params)) { $forwardCallbacks[] = $callback; } } return function (...$forwards) use ($forwardCallbacks) { foreach ($forwardCallbacks as $callback) { $callback(...$forwards); } }; }; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/LivewireManager.php
src/LivewireManager.php
<?php namespace Livewire; use Livewire\Mechanisms\PersistentMiddleware\PersistentMiddleware; use Livewire\Mechanisms\HandleRequests\HandleRequests; use Livewire\Mechanisms\HandleComponents\HandleComponents; use Livewire\Mechanisms\HandleComponents\ComponentContext; use Livewire\Mechanisms\FrontendAssets\FrontendAssets; use Livewire\Mechanisms\ExtendBlade\ExtendBlade; use Livewire\Features\SupportTesting\Testable; use Livewire\Features\SupportTesting\DuskTestable; use Livewire\Features\SupportLazyLoading\SupportLazyLoading; use Livewire\Features\SupportAutoInjectedAssets\SupportAutoInjectedAssets; class LivewireManager { protected LivewireServiceProvider $provider; public static $v4 = true; function setProvider(LivewireServiceProvider $provider) { $this->provider = $provider; } function provide($callback) { \Closure::bind($callback, $this->provider, $this->provider::class)(); } function component($name, $class = null) { $this->addComponent($name, class: $class); } function addComponent($name, $viewPath = null, $class = null) { app('livewire.finder')->addComponent($name, class: $class, viewPath: $viewPath); } function addLocation($viewPath = null, $classNamespace = null) { return app('livewire.finder')->addLocation(classNamespace: $classNamespace, viewPath: $viewPath); } function addNamespace($namespace, $viewPath = null, $classNamespace = null, $classPath = null, $classViewPath = null) { return app('livewire.finder')->addNamespace($namespace, classNamespace: $classNamespace, viewPath: $viewPath, classPath: $classPath, classViewPath: $classViewPath); } function componentHook($hook) { ComponentHookRegistry::register($hook); } function propertySynthesizer($synth) { app(HandleComponents::class)->registerPropertySynthesizer($synth); } function directive($name, $callback) { app(ExtendBlade::class)->livewireOnlyDirective($name, $callback); } function precompiler($callback) { app(ExtendBlade::class)->livewireOnlyPrecompiler($callback); } function prepareViewsForCompilationUsing(callable $callback) { app('livewire.compiler')->prepareViewsForCompilationUsing($callback); } function new($name, $id = null) { return app('livewire.factory')->create($name, $id); } /** * @deprecated This method will be removed in a future version. Use exists() instead. */ function isDiscoverable($componentNameOrClass) { return $this->exists($componentNameOrClass); } function exists($componentNameOrClass) { return app('livewire.factory')->exists($componentNameOrClass); } function resolveMissingComponent($resolver) { return app('livewire.factory')->resolveMissingComponent($resolver); } function mount($name, $params = [], $key = null, $slots = []) { return app(HandleComponents::class)->mount($name, $params, $key, $slots); } function snapshot($component, $context = null) { return app(HandleComponents::class)->snapshot($component, $context); } function fromSnapshot($snapshot) { return app(HandleComponents::class)->fromSnapshot($snapshot); } function listen($eventName, $callback) { return on($eventName, $callback); } function current() { return last(app(HandleComponents::class)::$componentStack); } function findSynth($keyOrTarget, $component) { return app(HandleComponents::class)->findSynth($keyOrTarget, $component); } function update($snapshot, $diff, $calls) { return app(HandleComponents::class)->update($snapshot, $diff, $calls); } function updateProperty($component, $path, $value) { $dummyContext = new ComponentContext($component, false); $updatedHook = app(HandleComponents::class)->updateProperty($component, $path, $value, $dummyContext); $updatedHook(); } function isLivewireRequest() { return app(HandleRequests::class)->isLivewireRequest(); } function componentHasBeenRendered() { return SupportAutoInjectedAssets::$hasRenderedAComponentThisRequest; } function forceAssetInjection() { SupportAutoInjectedAssets::$forceAssetInjection = true; } function setUpdateRoute($callback) { return app(HandleRequests::class)->setUpdateRoute($callback); } function getUriPrefix() { return app(HandleRequests::class)->getUriPrefix(); } function getUpdateUri() { return app(HandleRequests::class)->getUpdateUri(); } function setScriptRoute($callback) { return app(FrontendAssets::class)->setScriptRoute($callback); } function useScriptTagAttributes($attributes) { return app(FrontendAssets::class)->useScriptTagAttributes($attributes); } protected $queryParamsForTesting = []; protected $cookiesForTesting = []; protected $headersForTesting = []; function withUrlParams($params) { return $this->withQueryParams($params); } function withQueryParams($params) { $this->queryParamsForTesting = $params; return $this; } function withCookie($name, $value) { $this->cookiesForTesting[$name] = $value; return $this; } function withCookies($cookies) { $this->cookiesForTesting = array_merge($this->cookiesForTesting, $cookies); return $this; } function withHeaders($headers) { $this->headersForTesting = array_merge($this->headersForTesting, $headers); return $this; } function withoutLazyLoading() { SupportLazyLoading::disableWhileTesting(); return $this; } function test($name, $params = []) { return Testable::create( $name, $params, $this->queryParamsForTesting, $this->cookiesForTesting, $this->headersForTesting, ); } function visit($name, $args = []) { if (class_exists(\Pest\Browser\Api\Livewire::class)) { return \Pest\Browser\Api\Livewire::test($name, $args); } return DuskTestable::create($name, $params = [], $this->queryParamsForTesting); } function actingAs(\Illuminate\Contracts\Auth\Authenticatable $user, $driver = null) { Testable::actingAs($user, $driver); return $this; } function isRunningServerless() { return in_array($_ENV['SERVER_SOFTWARE'] ?? null, [ 'vapor', 'bref', ]); } function addPersistentMiddleware($middleware) { app(PersistentMiddleware::class)->addPersistentMiddleware($middleware); } function setPersistentMiddleware($middleware) { app(PersistentMiddleware::class)->setPersistentMiddleware($middleware); } function getPersistentMiddleware() { return app(PersistentMiddleware::class)->getPersistentMiddleware(); } function zap() { return app('livewire.zap'); } function flushState() { trigger('flush-state'); } function originalUrl() { if ($this->isLivewireRequest()) { return url()->to($this->originalPath()); } return url()->current(); } function originalPath() { if ($this->isLivewireRequest()) { $snapshot = json_decode(request('components.0.snapshot'), true); return data_get($snapshot, 'memo.path', 'POST'); } return request()->path(); } function originalMethod() { if ($this->isLivewireRequest()) { $snapshot = json_decode(request('components.0.snapshot'), true); return data_get($snapshot, 'memo.method', 'POST'); } return request()->method(); } function isCspSafe() { return config('livewire.csp_safe', false); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Attribute.php
src/Attribute.php
<?php namespace Livewire; use Livewire\Features\SupportAttributes\Attribute as BaseAttribute; abstract class Attribute extends BaseAttribute { // }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/WithFileUploads.php
src/WithFileUploads.php
<?php namespace Livewire; use Livewire\Features\SupportFileUploads\WithFileUploads as BaseWithFileUploads; trait WithFileUploads { use BaseWithFileUploads; }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Wireable.php
src/Wireable.php
<?php namespace Livewire; interface Wireable { public function toLivewire(); public static function fromLivewire($value); }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/helpers.php
src/helpers.php
<?php namespace Livewire; use ReflectionClass; use Illuminate\Support\Str; function str($string = null) { if (is_null($string)) return new class { public function __call($method, $params) { return Str::$method(...$params); } }; return Str::of($string); } function invade($obj) { return new class($obj) { public $obj; public $reflected; public function __construct($obj) { $this->obj = $obj; $this->reflected = new ReflectionClass($obj); } public function &__get($name) { $getProperty = function &() use ($name) { return $this->{$name}; }; $getProperty = $getProperty->bindTo($this->obj, get_class($this->obj)); return $getProperty(); } public function __set($name, $value) { $setProperty = function () use ($name, &$value) { $this->{$name} = $value; }; $setProperty = $setProperty->bindTo($this->obj, get_class($this->obj)); $setProperty(); } public function __call($name, $params) { $method = $this->reflected->getMethod($name); return $method->invoke($this->obj, ...$params); } }; } function once($fn) { $hasRun = false; return function (...$params) use ($fn, &$hasRun) { if ($hasRun) return; $hasRun = true; return $fn(...$params); }; } function of(...$params) { return $params; } function revert(&$variable) { $cache = $variable; return function () use (&$variable, $cache) { $variable = $cache; }; } function wrap($subject) { return new Wrapped($subject); } function pipe($subject) { return new Pipe($subject); } function trigger($name, ...$params) { return app(\Livewire\EventBus::class)->trigger($name, ...$params); } function on($name, $callback) { return app(\Livewire\EventBus::class)->on($name, $callback); } function after($name, $callback) { return app(\Livewire\EventBus::class)->after($name, $callback); } function before($name, $callback) { return app(\Livewire\EventBus::class)->before($name, $callback); } function off($name, $callback) { app(\Livewire\EventBus::class)->off($name, $callback); } function memoize($target) { static $memo = new \WeakMap; return new class ($target, $memo) { function __construct( protected $target, protected &$memo, ) {} function __call($method, $params) { $this->memo[$this->target] ??= []; $signature = $method . crc32(json_encode($params)); return $this->memo[$this->target][$signature] ??= $this->target->$method(...$params); } }; } function store($instance = null) { if (! $instance) $instance = app(\Livewire\Mechanisms\DataStore::class); return new class ($instance) { function __construct(protected $instance) {} function get($key, $default = null) { return app(\Livewire\Mechanisms\DataStore::class)->get($this->instance, $key, $default); } function set($key, $value) { return app(\Livewire\Mechanisms\DataStore::class)->set($this->instance, $key, $value); } function push($key, $value, $iKey = null) { return app(\Livewire\Mechanisms\DataStore::class)->push($this->instance, $key, $value, $iKey); } function find($key, $iKey = null, $default = null) { return app(\Livewire\Mechanisms\DataStore::class)->find($this->instance, $key, $iKey, $default); } function has($key, $iKey = null) { return app(\Livewire\Mechanisms\DataStore::class)->has($this->instance, $key, $iKey); } function unset($key, $iKey = null) { return app(\Livewire\Mechanisms\DataStore::class)->unset($this->instance, $key, $iKey); } }; }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Transparency.php
src/Transparency.php
<?php namespace Livewire; use Traversable; trait Transparency { public $target; function __toString() { return (string) $this->target; } function offsetExists(mixed $offset): bool { return isset($this->target[$offset]); } function offsetGet(mixed $offset): mixed { return $this->target[$offset]; } function offsetSet(mixed $offset, mixed $value): void { $this->target[$offset] = $value; } function offsetUnset(mixed $offset): void { unset($this->target[$offset]); } function getIterator(): Traversable { return (function () { foreach ($this->target as $key => $value) { yield $key => $value; } })(); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/ComponentHook.php
src/ComponentHook.php
<?php namespace Livewire; abstract class ComponentHook { protected $component; function setComponent($component) { $this->component = $component; } function callBoot(...$params) { if (method_exists($this, 'boot')) $this->boot(...$params); } function callMount(...$params) { if (method_exists($this, 'mount')) $this->mount(...$params); } function callHydrate(...$params) { if (method_exists($this, 'hydrate')) $this->hydrate(...$params); } function callUpdate($propertyName, $fullPath, $newValue) { $callbacks = []; if (method_exists($this, 'update')) $callbacks[] = $this->update($propertyName, $fullPath, $newValue); return function (...$params) use ($callbacks) { foreach ($callbacks as $callback) { if (is_callable($callback)) $callback(...$params); } }; } function callCall($method, $params, $returnEarly, $metadata, $componentContext) { $callbacks = []; if (method_exists($this, 'call')) $callbacks[] = $this->call($method, $params, $returnEarly, $metadata, $componentContext); return function (...$params) use ($callbacks) { foreach ($callbacks as $callback) { if (is_callable($callback)) $callback(...$params); } }; } function callRender(...$params) { $callbacks = []; if (method_exists($this, 'render')) $callbacks[] = $this->render(...$params); return function (...$params) use ($callbacks) { foreach ($callbacks as $callback) { if (is_callable($callback)) $callback(...$params); } }; } function callRenderIsland(...$params) { $callbacks = []; if (method_exists($this, 'renderIsland')) $callbacks[] = $this->renderIsland(...$params); return function (...$params) use ($callbacks) { foreach ($callbacks as $callback) { if (is_callable($callback)) $callback(...$params); } }; } function callDehydrate(...$params) { if (method_exists($this, 'dehydrate')) $this->dehydrate(...$params); } function callDestroy(...$params) { if (method_exists($this, 'destroy')) $this->destroy(...$params); } function callException(...$params) { if (method_exists($this, 'exception')) $this->exception(...$params); } function getProperties() { return $this->component->all(); } function getProperty($name) { return data_get($this->getProperties(), $name); } function storeSet($key, $value) { store($this->component)->set($key, $value); } function storePush($key, $value, $iKey = null) { store($this->component)->push($key, $value, $iKey); } function storeGet($key, $default = null) { return store($this->component)->get($key, $default); } function storeHas($key) { return store($this->component)->has($key); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/WireDirective.php
src/WireDirective.php
<?php namespace Livewire; use Stringable; use Illuminate\View\ComponentAttributeBag; use Illuminate\Contracts\Support\Htmlable; class WireDirective implements Htmlable, Stringable { public function __construct( public $name, public $directive, public $value, ) {} public function name() { return $this->name; } public function directive() { return $this->directive; } public function value() { return $this->value; } public function modifiers() { return str($this->directive) ->replace("wire:{$this->name}", '') ->explode('.') ->filter()->values(); } public function hasModifier($modifier) { return $this->modifiers()->contains($modifier); } public function toHtml() { return (new ComponentAttributeBag([$this->directive => $this->value]))->toHtml(); } public function toString() { return (string) $this; } public function __toString() { return (string) $this->value; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Livewire.php
src/Livewire.php
<?php namespace Livewire; use Illuminate\Support\Facades\Facade; /** * @method static void component($name, $class = null) * @method static void directive($name, $callback) * @method static \Livewire\Component new($name, $id = null) * @method static string mount($name, $params = [], $key = null) * @method static array snapshot($component) * @method static void fromSnapshot($snapshot) * @method static void listen($name, $callback) * @method static array update($snapshot, $diff, $calls) * @method static bool isLivewireRequest() * @method static void setUpdateRoute($callback) * @method static string getUpdateUri() * @method static void setScriptRoute($callback) * @method static void useScriptTagAttributes($attributes) * @method static \Livewire\LivewireManager withUrlParams($params) * @method static \Livewire\LivewireManager withQueryParams($params) * @method static \Livewire\Features\SupportTesting\Testable test($name, $params = []) * @method static \Livewire\LivewireManager actingAs($user, $driver = null) * @method static bool isRunningServerless() * @method static void addPersistentMiddleware($middleware) * @method static void setPersistentMiddleware($middleware) * @method static array getPersistentMiddleware() * @method static void flushState() * @method static string originalUrl() * @method static string originalPath() * @method static string originalMethod() * @method static \Livewire\LivewireManager withoutLazyLoading() * * @see \Livewire\LivewireManager */ class Livewire extends Facade { public static function getFacadeAccessor() { return \Livewire\LivewireManager::class; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/ImplicitlyBoundMethod.php
src/ImplicitlyBoundMethod.php
<?php namespace Livewire; use Illuminate\Container\BoundMethod; use Illuminate\Contracts\Routing\UrlRoutable as ImplicitlyBindable; use Illuminate\Database\Eloquent\ModelNotFoundException; use ReflectionClass; use ReflectionNamedType; class ImplicitlyBoundMethod extends BoundMethod { protected static function getMethodDependencies($container, $callback, array $parameters = []) { $dependencies = []; $paramIndex = 0; foreach (static::getCallReflector($callback)->getParameters() as $parameter) { static::substituteNameBindingForCallParameter($parameter, $parameters, $paramIndex); static::substituteImplicitBindingForCallParameter($container, $parameter, $parameters); static::addDependencyForCallParameter($container, $parameter, $parameters, $dependencies); } return array_values(array_merge($dependencies, $parameters)); } protected static function substituteNameBindingForCallParameter($parameter, array &$parameters, int &$paramIndex) { // check if we have a candidate for name/value binding if (! array_key_exists($paramIndex, $parameters)) { return; } if ($parameter->isVariadic()) { // this last param will pick up the rest - reindex any remaining parameters $parameters = array_merge( array_filter($parameters, function ($key) { return ! is_int($key); }, ARRAY_FILTER_USE_KEY), array_values(array_filter($parameters, function ($key) { return is_int($key); }, ARRAY_FILTER_USE_KEY)) ); return; } // stop if this one is due for dependency injection if (! is_null($className = static::getClassForDependencyInjection($parameter)) && ! $parameters[$paramIndex] instanceof $className) { return; } if (! array_key_exists($paramName = $parameter->getName(), $parameters)) { // have a parameter value that is bound by sequential order // and not yet bound by name, so bind it to parameter name $parameters[$paramName] = $parameters[$paramIndex]; unset($parameters[$paramIndex]); $paramIndex++; } } protected static function substituteImplicitBindingForCallParameter($container, $parameter, array &$parameters) { $paramName = $parameter->getName(); // check if we have a candidate for implicit binding if (is_null($className = static::getClassForImplicitBinding($parameter))) { return; } // Check if the value we have for this param is an instance // of the desired class, attempt implicit binding if not if (array_key_exists($paramName, $parameters) && ! $parameters[$paramName] instanceof $className) { $parameters[$paramName] = static::getImplicitBinding($container, $className, $parameters[$paramName]); } elseif (array_key_exists($className, $parameters) && ! $parameters[$className] instanceof $className) { $parameters[$className] = static::getImplicitBinding($container, $className, $parameters[$className]); } } protected static function getClassForDependencyInjection($parameter) { $className = static::getParameterClassName($parameter); if (is_null($className)) return null; if (static::isEnum($parameter)) return null; if (! static::implementsInterface($parameter)) return $className; return null; } protected static function getClassForImplicitBinding($parameter) { $className = static::getParameterClassName($parameter); if (is_null($className)) return null; if (static::isEnum($parameter)) return $className; if (static::implementsInterface($parameter)) return $className; return null; } protected static function getImplicitBinding($container, $className, $value) { if (is_null($value)) { return null; } if ((new ReflectionClass($className))->isEnum()) { return $className::tryFrom($value); } $model = $container->make($className)->resolveRouteBinding($value); if (! $model) { throw (new ModelNotFoundException)->setModel($className, [$value]); } return $model; } public static function getParameterClassName($parameter) { $type = $parameter->getType(); if (! $type) return null; if (! $type instanceof ReflectionNamedType) return null; return (! $type->isBuiltin()) ? $type->getName() : null; } public static function implementsInterface($parameter) { return (new ReflectionClass($parameter->getType()->getName()))->implementsInterface(ImplicitlyBindable::class); } public static function isEnum($parameter) { return (new ReflectionClass($parameter->getType()->getName()))->isEnum(); } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/WithoutUrlPagination.php
src/WithoutUrlPagination.php
<?php namespace Livewire; use Livewire\Features\SupportPagination\WithoutUrlPagination as BaseWithoutUrlPagination; trait WithoutUrlPagination { use BaseWithoutUrlPagination; }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Wrapped.php
src/Wrapped.php
<?php namespace Livewire; class Wrapped { protected $fallback; function __construct(public $target) {} function withFallback($fallback) { $this->fallback = $fallback; return $this; } function __call($method, $params) { if (! method_exists($this->target, $method)) return value($this->fallback); try { return ImplicitlyBoundMethod::call(app(), [$this->target, $method], $params); } catch (\Throwable $e) { $shouldPropagate = true; $stopPropagation = function () use (&$shouldPropagate) { $shouldPropagate = false; }; trigger('exception', $this->target, $e, $stopPropagation); $shouldPropagate && throw $e; } } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Pipe.php
src/Pipe.php
<?php namespace Livewire; class Pipe implements \Stringable, \ArrayAccess, \IteratorAggregate { use Transparency; function __construct($target) { $this->target = $target; } function __invoke(...$params) { if (empty($params)) return $this->target; [ $before, $through, $after ] = [ [], null, [] ]; foreach ($params as $key => $param) { if (! $through) { if (is_callable($param)) $through = $param; else $before[$key] = $param; } else { $after[$key] = $param; } } $params = [ ...$before, $this->target, ...$after ]; $this->target = $through(...$params); return $this; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Form.php
src/Form.php
<?php namespace Livewire; use Livewire\Features\SupportFormObjects\Form as BaseForm; class Form extends BaseForm { // }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/EventBus.php
src/EventBus.php
<?php declare(strict_types=1); namespace Livewire; class EventBus { protected array $listeners = []; protected array $listenersAfter = []; protected array $listenersBefore = []; public function boot(): void { app()->singleton($this::class); } public function on(string $name, callable $callback): callable { $this->listeners[$name][] = $callback; return fn() => $this->off($name, $callback); } public function before(string $name, callable $callback): callable { $this->listenersBefore[$name][] = $callback; return fn() => $this->off($name, $callback); } public function after(string $name, callable $callback): callable { $this->listenersAfter[$name][] = $callback; return fn() => $this->off($name, $callback); } public function off(string $name, callable $callback): void { if (isset($this->listeners[$name])) { $index = array_search($callback, $this->listeners[$name], true); if ($index !== false) { unset($this->listeners[$name][$index]); return; } } if (isset($this->listenersAfter[$name])) { $index = array_search($callback, $this->listenersAfter[$name], true); if ($index !== false) { unset($this->listenersAfter[$name][$index]); return; } } if (isset($this->listenersBefore[$name])) { $index = array_search($callback, $this->listenersBefore[$name], true); if ($index !== false) { unset($this->listenersBefore[$name][$index]); } } } public function trigger(string $name, ...$params): callable { $middlewares = []; $listeners = []; if (isset($this->listenersBefore[$name])) { $listeners = $this->listenersBefore[$name]; } if (isset($this->listeners[$name])) { $listeners = array_merge($listeners, $this->listeners[$name]); } if (isset($this->listenersAfter[$name])) { $listeners = array_merge($listeners, $this->listenersAfter[$name]); } foreach ($listeners as $callback) { $result = $callback(...$params); if ($result !== null) { $middlewares[] = $result; } } return function (&$forward = null, ...$extras) use ($middlewares) { foreach ($middlewares as $finisher) { if ($finisher === null) continue; $finisher = is_array($finisher) ? end($finisher) : $finisher; $result = $finisher($forward, ...$extras); $forward = $result ?? $forward; } return $forward; }; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/WithPagination.php
src/WithPagination.php
<?php namespace Livewire; use Livewire\Features\SupportPagination\HandlesPagination; trait WithPagination { use HandlesPagination; }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Component.php
src/Component.php
<?php namespace Livewire; use Livewire\Features\SupportValidation\HandlesValidation; use Livewire\Features\SupportStreaming\HandlesStreaming; use Livewire\Features\SupportSlots\HandlesSlots; use Livewire\Features\SupportReleaseTokens\HandlesReleaseTokens; use Livewire\Features\SupportRedirects\HandlesRedirects; use Livewire\Features\SupportPageComponents\HandlesPageComponents; use Livewire\Features\SupportJsEvaluation\HandlesJsEvaluation; use Livewire\Features\SupportIslands\HandlesIslands; use Livewire\Features\SupportFormObjects\HandlesFormObjects; use Livewire\Features\SupportEvents\HandlesEvents; use Livewire\Features\SupportHtmlAttributeForwarding\HandlesHtmlAttributeForwarding; use Livewire\Features\SupportDisablingBackButtonCache\HandlesDisablingBackButtonCache; use Livewire\Features\SupportAttributes\HandlesAttributes; use Livewire\Exceptions\PropertyNotFoundException; use Livewire\Concerns\InteractsWithProperties; use Illuminate\Support\Traits\Macroable; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use BadMethodCallException; abstract class Component { use Macroable { __call as macroCall; } use AuthorizesRequests; use InteractsWithProperties; use HandlesEvents; use HandlesIslands; use HandlesRedirects; use HandlesStreaming; use HandlesAttributes; use HandlesValidation; use HandlesFormObjects; use HandlesJsEvaluation; use HandlesReleaseTokens; use HandlesPageComponents; use HandlesDisablingBackButtonCache; use HandlesSlots; use HandlesHtmlAttributeForwarding; protected $__id; protected $__name; function id() { return $this->getId(); } function setId($id) { $this->__id = $id; } function getId() { return $this->__id; } function setName($name) { $this->__name = $name; } function getName() { return $this->__name; } function renderless() { $this->skipRender(); } function skipRender($html = null) { if (store($this)->has('forceRender')) { return; } store($this)->set('skipRender', $html ?: true); } function forceRender() { store($this)->set('forceRender', true); } function skipMount() { store($this)->set('skipMount', true); } function skipHydrate() { store($this)->set('skipHydrate', true); } function hasProvidedView() { return method_exists($this, 'view'); } function getProvidedView() { return $this->view(); } function __isset($property) { try { $value = $this->__get($property); if (isset($value)) { return true; } } catch(PropertyNotFoundException $ex) {} return false; } function __get($property) { $value = 'noneset'; $returnValue = function ($newValue) use (&$value) { $value = $newValue; }; $finish = trigger('__get', $this, $property, $returnValue); $value = $finish($value); if ($value === 'noneset') { throw new PropertyNotFoundException($property, $this->getName()); } return $value; } function __unset($property) { trigger('__unset', $this, $property); } function __call($method, $params) { $value = 'noneset'; $returnValue = function ($newValue) use (&$value) { $value = $newValue; }; $finish = trigger('__call', $this, $method, $params, $returnValue); $value = $finish($value); if ($value !== 'noneset') { return $value; } if (static::hasMacro($method)) { return $this->macroCall($method, $params); } throw new BadMethodCallException(sprintf( 'Method %s::%s does not exist.', static::class, $method )); } public function tap($callback) { $callback($this); return $this; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Compiler/Compiler.php
src/Compiler/Compiler.php
<?php namespace Livewire\Compiler; use Livewire\Compiler\Parser\SingleFileParser; use Livewire\Compiler\Parser\MultiFileParser; class Compiler { protected $prepareViewsForCompilationUsing = []; public function __construct( public CacheManager $cacheManager, ) {} public function compile(string $path): string { if (! file_exists($path)) { throw new \Exception("File not found: [{$path}]"); } if ( (! $this->cacheManager->hasBeenCompiled($path)) || $this->cacheManager->isExpired($path) ) { $this->compilePath($path); } return $this->cacheManager->getClassName($path); } public function compilePath(string $path): void { $parser = is_file($path) ? SingleFileParser::parse($this, $path) : MultiFileParser::parse($this, $path); $viewFileName = $this->cacheManager->getViewPath($path); $placeholderFileName = null; $scriptFileName = null; $placeholderContents = $parser->generatePlaceholderContents(); $scriptContents = $parser->generateScriptContents(); if ($placeholderContents !== null) { $placeholderFileName = $this->cacheManager->getPlaceholderPath($path); $this->cacheManager->writePlaceholderFile($path, $placeholderContents); } if ($scriptContents !== null) { $scriptFileName = $this->cacheManager->getScriptPath($path); $this->cacheManager->writeScriptFile($path, $scriptContents); } $this->cacheManager->writeClassFile($path, $parser->generateClassContents( $viewFileName, $placeholderFileName, $scriptFileName, )); $this->cacheManager->writeViewFile($path, $parser->generateViewContents()); } public function clearCompiled($output = null) { $this->cacheManager->clearCompiledFiles($output); } public function prepareViewsForCompilationUsing($callback) { $this->prepareViewsForCompilationUsing[] = $callback; } public function prepareViewForCompilation($contents, $path) { foreach ($this->prepareViewsForCompilationUsing as $callback) { $contents = $callback($contents, $path); } return $contents; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Compiler/UnitTest.php
src/Compiler/UnitTest.php
<?php namespace Livewire\Compiler; use Livewire\Component; use Livewire\Compiler\Parser\SingleFileParser; use Livewire\Compiler\Parser\MultiFileParser; use Livewire\Compiler\Compiler; use Livewire\Compiler\CacheManager; use Illuminate\Support\Facades\File; use PHPUnit\Framework\Attributes\DataProvider; class UnitTest extends \Tests\TestCase { protected $tempPath; protected $cacheDir; public function setUp(): void { parent::setUp(); $this->tempPath = sys_get_temp_dir() . '/livewire_compiler_test_' . uniqid(); $this->cacheDir = $this->tempPath . '/cache'; File::makeDirectory($this->tempPath, 0755, true); File::makeDirectory($this->cacheDir, 0755, true); } protected function tearDown(): void { if (File::exists($this->tempPath)) { File::deleteDirectory($this->tempPath); } parent::tearDown(); } public function test_can_compile_sfc_component() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $class = $compiler->compile(__DIR__ . '/Fixtures/sfc-component.blade.php'); $this->assertInstanceOf(Component::class, new $class); } public function test_can_parse_sfc_component() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component.blade.php'); $classContents = $parser->generateClassContents('view-path.blade.php'); $scriptContents = $parser->generateScriptContents(); $viewContents = $parser->generateViewContents(); $this->assertStringContainsString('new class extends Component', $classContents); $this->assertStringContainsString('use Livewire\Component;', $classContents); $this->assertStringContainsString("return app('view')->file('view-path.blade.php', \$data);", $classContents); $this->assertStringNotContainsString('new class extends Component', $viewContents); $this->assertStringNotContainsString('new class extends Component', $scriptContents); $this->assertStringContainsString("console.log('Hello from script');", $scriptContents); $this->assertStringNotContainsString("console.log('Hello from script');", $classContents); $this->assertStringNotContainsString("console.log('Hello from script');", $viewContents); $this->assertStringContainsString('<div>{{ $message }}</div>', $viewContents); // Ensure that use statements are also available inside the view... $this->assertStringContainsString('use Livewire\Component;', $viewContents); $this->assertStringNotContainsString('<div>{{ $message }}</div>', $classContents); $this->assertStringNotContainsString('<div>{{ $message }}</div>', $scriptContents); } public function test_wont_parse_blade_script() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component-with-blade-script.blade.php'); $classContents = $parser->generateClassContents('view-path.blade.php'); $scriptContents = $parser->generateScriptContents(); $viewContents = $parser->generateViewContents(); $this->assertStringContainsString('new class extends Component', $classContents); $this->assertStringContainsString('use Livewire\Component;', $classContents); $this->assertStringContainsString("return app('view')->file('view-path.blade.php', \$data);", $classContents); $this->assertStringNotContainsString('new class extends Component', $viewContents); // Script should NOT be extracted when wrapped in @script/@endscript $this->assertNull($scriptContents); $this->assertStringNotContainsString("console.log('Hello from script');", $classContents); // The script content should remain in the view portion when wrapped in @script/@endscript $this->assertStringContainsString("console.log('Hello from script');", $viewContents); $this->assertStringContainsString('<div>{{ $message }}</div>', $viewContents); // Ensure that use statements are also available inside the view... $this->assertStringContainsString('use Livewire\Component;', $viewContents); $this->assertStringNotContainsString('<div>{{ $message }}</div>', $classContents); } public function test_wont_parse_nested_script() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component-with-nested-script.blade.php'); $classContents = $parser->generateClassContents('view-path.blade.php'); $scriptContents = $parser->generateScriptContents(); $viewContents = $parser->generateViewContents(); $this->assertStringContainsString('new class extends Component', $classContents); $this->assertStringContainsString('use Livewire\Component;', $classContents); $this->assertStringContainsString("return app('view')->file('view-path.blade.php', \$data);", $classContents); $this->assertStringNotContainsString('new class extends Component', $viewContents); // Only the root-level script should be extracted $this->assertStringContainsString("console.log('This SHOULD be extracted - it is at root level');", $scriptContents); $this->assertStringNotContainsString("console.log('This should NOT be extracted - it is nested inside div');", $scriptContents); // The nested script should remain in the view portion $this->assertStringContainsString("console.log('This should NOT be extracted - it is nested inside div');", $viewContents); $this->assertStringContainsString('<div>', $viewContents); $this->assertStringContainsString('{{ $message }}', $viewContents); } public function test_wont_parse_scripts_inside_assets_or_script_directives() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component-with-assets-and-script-directives.blade.php'); $classContents = $parser->generateClassContents('view-path.blade.php'); $scriptContents = $parser->generateScriptContents(); $viewContents = $parser->generateViewContents(); $this->assertStringContainsString('new class extends Component', $classContents); $this->assertStringContainsString('use Livewire\Component;', $classContents); $this->assertStringContainsString("return app('view')->file('view-path.blade.php', \$data);", $classContents); $this->assertStringNotContainsString('new class extends Component', $viewContents); // Scripts inside @assets/@endassets should NOT be extracted $this->assertNull($scriptContents); $this->assertStringNotContainsString("console.log('This should NOT be extracted - it is inside @assets');", $classContents); $this->assertStringNotContainsString("console.log('This should NOT be extracted - it is inside @script');", $classContents); // Both scripts should remain in the view portion when wrapped in directives $this->assertStringContainsString("console.log('This should NOT be extracted - it is inside @assets');", $viewContents); $this->assertStringContainsString("console.log('This should NOT be extracted - it is inside @script');", $viewContents); $this->assertStringContainsString('@assets', $viewContents); $this->assertStringContainsString('@endassets', $viewContents); $this->assertStringContainsString('@script', $viewContents); $this->assertStringContainsString('@endscript', $viewContents); } public function test_script_hoists_imports_and_wraps_in_export_function() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component-with-imports.blade.php'); $scriptContents = $parser->generateScriptContents(); // Check that imports are hoisted to the top $this->assertStringContainsString("import { Alpine } from 'alpinejs'", $scriptContents); $this->assertStringContainsString("import { debounce } from './utils'", $scriptContents); // Check that the script is wrapped in export function run() $this->assertMatchesRegularExpression('/export function run\([^)]*\) \{/', $scriptContents); $this->assertStringContainsString("console.log('Component initialized');", $scriptContents); // Ensure imports appear before the export function $importPos = strpos($scriptContents, 'import'); $exportPos = strpos($scriptContents, 'export function run'); $this->assertLessThan($exportPos, $importPos, 'Imports should appear before export function'); // Ensure the function body contains the actual logic (not the imports) preg_match('/export function run\([^)]*\) \{(.+)\}/s', $scriptContents, $matches); $functionBody = $matches[1] ?? ''; $this->assertStringNotContainsString('import', $functionBody, 'Import statements should not be in function body'); $this->assertStringContainsString("console.log('Component initialized');", $functionBody); } public function test_script_wraps_in_export_function_even_without_imports() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component.blade.php'); $scriptContents = $parser->generateScriptContents(); // Check that the script is wrapped in export function run() even without imports $this->assertMatchesRegularExpression('/export function run\([^)]*\) \{/', $scriptContents); $this->assertStringContainsString("console.log('Hello from script');", $scriptContents); // Ensure no import statements are present $this->assertStringNotContainsString('import', $scriptContents); } public function test_parser_adds_trailing_semicolon_to_class_contents() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = SingleFileParser::parse($compiler, __DIR__ . '/Fixtures/sfc-component-without-trailing-semicolon.blade.php'); $classContents = $parser->generateClassContents('view-path.blade.php'); $this->assertStringContainsString('};', $classContents); } public function test_can_compile_mfc_component() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $class = $compiler->compile(__DIR__ . '/Fixtures/mfc-component'); $this->assertInstanceOf(Component::class, new $class); } public function test_can_parse_mfc_component() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $parser = MultiFileParser::parse($compiler, __DIR__ . '/Fixtures/mfc-component'); $classContents = $parser->generateClassContents('view-path.blade.php'); $scriptContents = $parser->generateScriptContents(); $viewContents = $parser->generateViewContents(); $this->assertStringContainsString('new class extends Component', $classContents); $this->assertStringContainsString('use Livewire\Component;', $classContents); $this->assertStringContainsString("return app('view')->file('view-path.blade.php', \$data);", $classContents); $this->assertStringNotContainsString('new class extends Component', $viewContents); $this->assertStringNotContainsString('new class extends Component', $scriptContents); $this->assertStringContainsString("console.log('Hello from script');", $scriptContents); $this->assertStringNotContainsString("console.log('Hello from script');", $classContents); $this->assertStringNotContainsString("console.log('Hello from script');", $viewContents); $this->assertStringContainsString('<div>{{ $message }}</div>', $viewContents); // Ensure that use statements are NOT available inside the view when parsing a multi-file component... $this->assertStringNotContainsString('use Livewire\Component;', $viewContents); $this->assertStringNotContainsString('<div>{{ $message }}</div>', $classContents); $this->assertStringNotContainsString('<div>{{ $message }}</div>', $scriptContents); } public function test_can_parse_placeholder_directive() { $compiler = new Compiler($cacheManager = new CacheManager($this->cacheDir)); $class = $compiler->compile(__DIR__ . '/Fixtures/sfc-component-with-placeholder.blade.php'); $classContents = file_get_contents($cacheManager->getClassPath(__DIR__ . '/Fixtures/sfc-component-with-placeholder.blade.php')); $viewContents = file_get_contents($cacheManager->getViewPath(__DIR__ . '/Fixtures/sfc-component-with-placeholder.blade.php')); $placeholderContents = file_get_contents($cacheManager->getPlaceholderPath(__DIR__ . '/Fixtures/sfc-component-with-placeholder.blade.php')); $this->assertStringNotContainsString('@placeholder', $viewContents); $this->assertStringContainsString('public function placeholder()', $classContents); $this->assertStringContainsString('Loading...', $placeholderContents); } public function test_ignores_placeholders_in_islands() { $compiler = new Compiler($cacheManager = new CacheManager($this->cacheDir)); $class = $compiler->compile(__DIR__ . '/Fixtures/sfc-component-with-placeholder-in-island.blade.php'); $classContents = file_get_contents($cacheManager->getClassPath(__DIR__ . '/Fixtures/sfc-component-with-placeholder-in-island.blade.php')); $viewContents = file_get_contents($cacheManager->getViewPath(__DIR__ . '/Fixtures/sfc-component-with-placeholder-in-island.blade.php')); $this->assertStringContainsString('@placeholder', $viewContents); $this->assertStringNotContainsString('public function placeholder()', $classContents); } public function test_can_re_compile_simple_sfc_component() { $compiler = new Compiler(new CacheManager($this->cacheDir)); $class = $compiler->compile(__DIR__ . '/Fixtures/sfc-component.blade.php'); $class = $compiler->compile(__DIR__ . '/Fixtures/sfc-component.blade.php'); $this->assertInstanceOf(Component::class, new $class); } public function test_compiler_will_recompile_if_source_file_is_older_than_compiled_file() { $compiler = new Compiler($cacheManager = new CacheManager($this->cacheDir)); // First compilation $compiler->compile($sourcePath = __DIR__ . '/Fixtures/sfc-component.blade.php'); $compiledPath = $cacheManager->getClassPath($sourcePath); // Set the compiled file modification time to 10 seconds ago... $staleFileMtime = filemtime($sourcePath) - 10; touch($compiledPath, $staleFileMtime); $this->assertEquals($staleFileMtime, filemtime($compiledPath)); // Compile again $compiler->compile($sourcePath); // Assert the file was modified $this->assertNotEquals($staleFileMtime, filemtime($compiledPath)); // Set the compiled file modification time to 10 seconds ago... $freshFileMtime = filemtime($sourcePath) + 10; touch($compiledPath, $freshFileMtime); $compiler->compile($sourcePath); $this->assertEquals($freshFileMtime, filemtime($compiledPath)); } public function test_can_hook_into_sfc_compilation() { $compiler = new Compiler($cacheManager = new CacheManager($this->cacheDir)); $compiler->prepareViewsForCompilationUsing(function ($contents) { return str_replace('div', 'span', $contents); }); $compiler->compile($sourcePath = __DIR__ . '/Fixtures/sfc-component.blade.php'); $viewContents = file_get_contents($cacheManager->getViewPath($sourcePath)); $this->assertStringContainsString('<span>{{ $message }}</span>', $viewContents); } public function test_can_hook_into_mfc_compilation() { $compiler = new Compiler($cacheManager = new CacheManager($this->cacheDir)); $compiler->prepareViewsForCompilationUsing(function ($contents) { return str_replace('div', 'span', $contents); }); $compiler->compile($sourcePath = __DIR__ . '/Fixtures/mfc-component'); $viewContents = file_get_contents($cacheManager->getViewPath($sourcePath)); $this->assertStringContainsString('<span>{{ $message }}</span>', $viewContents); } #[DataProvider('classReturnProvider')] public function test_anonymous_class_has_return_statement_added_if_required($classContents, $expectedOutput) { $parser = new SingleFileParser( path: '', contents: '', scriptPortion: null, classPortion: $classContents, placeholderPortion: null, viewPortion: '', ); $generatedClassContents = $parser->generateClassContents(); $this->assertEquals($expectedOutput, $generatedClassContents); } public static function classReturnProvider() { return [ [ <<<'EOT' <?php return new class extends \Livewire\Component { public $message = 'Hello World'; }; ?> EOT, <<<'EOT' <?php return new class extends \Livewire\Component { public $message = 'Hello World'; }; EOT, ], [ <<<'EOT' <?php new class extends \Livewire\Component { public $message = 'Hello World'; }; ?> EOT, <<<'EOT' <?php return new class extends \Livewire\Component { public $message = 'Hello World'; }; EOT, ], [ <<<'EOT' <?php return new class extends \Livewire\Component { public $message = 'Hello World'; }; ?> EOT, <<<'EOT' <?php return new class extends \Livewire\Component { public $message = 'Hello World'; }; EOT, ], [ <<<'EOT' <?php use Livewire\Component; new class extends Component { public function getData() { return new Collection([]); } }; ?> EOT, <<<'EOT' <?php use Livewire\Component; return new class extends Component { public function getData() { return new Collection([]); } }; EOT, ], [ <<<'EOT' <?php use Livewire\Component; new class extends Component { public function getData() { return new class extends Model { protected $table = 'users'; }; } }; ?> EOT, <<<'EOT' <?php use Livewire\Component; return new class extends Component { public function getData() { return new class extends Model { protected $table = 'users'; }; } }; EOT, ], [ <<<'EOT' <?php use Livewire\Attributes\Layout; use Livewire\Component; new #[Layout('layouts.app')] class extends Component { public function getData() { return new class extends Model { protected $table = 'users'; }; } }; ?> EOT, <<<'EOT' <?php use Livewire\Attributes\Layout; use Livewire\Component; return new #[Layout('layouts.app')] class extends Component { public function getData() { return new class extends Model { protected $table = 'users'; }; } }; EOT, ], [ <<<'EOT' <?php use Livewire\Attributes\Layout; use Livewire\Component; new #[Layout('layouts.app')] class extends Component { public function getData() { return new class extends Model { protected $table = 'users'; }; } }; ?> EOT, <<<'EOT' <?php use Livewire\Attributes\Layout; use Livewire\Component; return new #[Layout('layouts.app')] class extends Component { public function getData() { return new class extends Model { protected $table = 'users'; }; } }; EOT, ], ]; } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Compiler/CacheManager.php
src/Compiler/CacheManager.php
<?php namespace Livewire\Compiler; use Illuminate\Support\Facades\File; class CacheManager { public function __construct( public string $cacheDirectory, ) {} public function hasBeenCompiled(string $sourcePath): bool { $classPath = $this->getClassPath($sourcePath); return file_exists($classPath); } public function isExpired(string $sourcePath): bool { $sourceModificationTime = $this->getLatestFileModificationTimeOfSource($sourcePath); $compiledModificationTime = $this->getLatestFileModificationTimeOfCompiledFiles($sourcePath); return $sourceModificationTime > $compiledModificationTime; } public function getLatestFileModificationTimeOfSource(string $sourcePath): int { if (is_dir($sourcePath)) { return max(array_map('filemtime', glob($sourcePath . '/*'))); } return filemtime($sourcePath); } public function getLatestFileModificationTimeOfCompiledFiles(string $sourcePath): int { $classPath = $this->getClassPath($sourcePath); $viewPath = $this->getViewPath($sourcePath); $scriptPath = $this->getScriptPath($sourcePath); $times = []; foreach ([$classPath, $viewPath, $scriptPath] as $path) { if (file_exists($path)) { $times[] = filemtime($path); } } return empty($times) ? 0 : min($times); } public function getClassName(string $sourcePath): string { $instance = require $this->getClassPath($sourcePath); return $instance::class; } public function getHash(string $sourcePath): string { return substr(md5($sourcePath), 0, 8); } public function getClassPath(string $sourcePath): string { $hash = $this->getHash($sourcePath); return $this->cacheDirectory . '/classes/' . $hash . '.php'; } public function getViewPath(string $sourcePath): string { $hash = $this->getHash($sourcePath); return $this->cacheDirectory . '/views/' . $hash . '.blade.php'; } public function getScriptPath(string $sourcePath): string { $hash = $this->getHash($sourcePath); return $this->cacheDirectory . '/scripts/' . $hash . '.js'; } public function getPlaceholderPath(string $sourcePath): string { $hash = $this->getHash($sourcePath); return $this->cacheDirectory . '/placeholders/' . $hash . '.blade.php'; } public function writeClassFile(string $sourcePath, string $contents): void { $this->invalidateOpCache($sourcePath); $classPath = $this->getClassPath($sourcePath); File::ensureDirectoryExists($this->cacheDirectory . '/classes'); File::put($classPath, $contents); } public function writeViewFile(string $sourcePath, string $contents): void { $viewPath = $this->getViewPath($sourcePath); File::ensureDirectoryExists($this->cacheDirectory . '/views'); File::put($viewPath, $contents); $this->mutateFileModificationTime($viewPath); } public function writeScriptFile(string $sourcePath, string $contents): void { $scriptPath = $this->getScriptPath($sourcePath); File::ensureDirectoryExists($this->cacheDirectory . '/scripts'); File::put($scriptPath, $contents); } public function writePlaceholderFile(string $sourcePath, string $contents): void { $placeholderPath = $this->getPlaceholderPath($sourcePath); File::ensureDirectoryExists($this->cacheDirectory . '/placeholders'); File::put($placeholderPath, $contents); $this->mutateFileModificationTime($placeholderPath); } public function writeIslandFile(string $sourcePath, string $contents): void { $viewPath = $this->getViewPath($sourcePath); File::ensureDirectoryExists($this->cacheDirectory . '/views'); File::put($viewPath, $contents); $this->mutateFileModificationTime($viewPath); } public function invalidateOpCache(string $sourcePath): void { if (function_exists('opcache_invalidate')) { opcache_invalidate($sourcePath, true); } } public function mutateFileModificationTime(string $path): void { // This is a fix for a gnarly issue: blade's compiler uses filemtimes to determine if a compiled view has become expired. // AND it's comparison includes equals like this: $path >= $cachedPath // AND file_put_contents won't update the filemtime if the contents are the same // THEREFORE because we are creating a blade file at the same "second" that it is compiled // both the source file and the cached file's filemtime's match, therefore it become's in a perpetual state // of always being expired. So we mutate the source file to be one second behind so that the cached // view file is one second ahead. Phew. this one took a minute to find lol. $original = filemtime($path); touch($path, $original - 1); } public function clearCompiledFiles($output = null): void { try { $cacheDirectory = $this->cacheDirectory; if (is_dir($cacheDirectory)) { // Count files before clearing for informative output $totalFiles = 0; foreach (['classes', 'views', 'scripts', 'placeholders'] as $subdir) { $path = $cacheDirectory . '/' . $subdir; if (is_dir($path)) { $totalFiles += count(glob($path . '/*')); } } // Use the same cleanup approach as our clear command File::deleteDirectory($cacheDirectory); // Recreate the directory structure File::makeDirectory($cacheDirectory . '/classes', 0755, true); File::makeDirectory($cacheDirectory . '/views', 0755, true); File::makeDirectory($cacheDirectory . '/scripts', 0755, true); File::makeDirectory($cacheDirectory . '/placeholders', 0755, true); // Recreate .gitignore File::put($cacheDirectory . '/.gitignore', "*\n!.gitignore"); } } catch (\Exception $e) { // Silently fail to avoid breaking view:clear if there's an issue // But we can log it if output is available if ($output && method_exists($output, 'writeln')) { $output->writeln("<comment>1Note: Could not clear Livewire compiled files.</comment>"); } } } }
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Compiler/Fixtures/sfc-component-with-assets-and-script-directives.blade.php
src/Compiler/Fixtures/sfc-component-with-assets-and-script-directives.blade.php
<?php use Livewire\Component; new class extends Component { // }; ?> <div> {{-- An unexamined life is not worth living. - Socrates --}} </div> @assets <script> console.log('This should NOT be extracted - it is inside @assets'); </script> @endassets @script <script> console.log('This should NOT be extracted - it is inside @script'); </script> @endscript
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Compiler/Fixtures/sfc-component-with-imports.blade.php
src/Compiler/Fixtures/sfc-component-with-imports.blade.php
<?php use Livewire\Component; new class extends Component { public $message = 'Hello World'; }; ?> <div>{{ $message }}</div> <script> import { Alpine } from 'alpinejs' import { debounce } from './utils' console.log('Component initialized'); Alpine.data('myComponent', () => ({ init() { debounce(() => console.log('Debounced'), 100); } })); </script>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false
livewire/livewire
https://github.com/livewire/livewire/blob/f2f58e728b8e834780be780ee727a85e9513d56b/src/Compiler/Fixtures/sfc-component-with-nested-script.blade.php
src/Compiler/Fixtures/sfc-component-with-nested-script.blade.php
<?php use Livewire\Component; new class extends Component { public $message = 'Hello World'; }; ?> <div> {{ $message }} <script> console.log('This should NOT be extracted - it is nested inside div'); </script> </div> <script> console.log('This SHOULD be extracted - it is at root level'); </script>
php
MIT
f2f58e728b8e834780be780ee727a85e9513d56b
2026-01-04T15:02:34.292445Z
false