Skip to content

Commit

Permalink
Fix ServiceProvider Fault
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe authored Sep 23, 2023
1 parent e7c10c1 commit fb476e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/Features/AutoInjectRappasoftAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,33 @@ public static function provide(): void

app('events')->listen(RequestHandled::class, function ($handled) {

if (app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) {
if (! static::$forceAssetInjection && config('livewire-tables.inject_assets', true) === false) {
return;

Check warning on line 31 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L31

Added line #L31 was not covered by tests
}
if (! str($handled->response->headers->get('content-type'))->contains('text/html')) {
return;
}
if (! method_exists($handled->response, 'status') || $handled->response->status() !== 200) {
return;
}

if (! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent')) {
return;

Check warning on line 41 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L41

Added line #L41 was not covered by tests
}

if ((! static::$hasRenderedAComponentThisRequest) && (! static::$forceAssetInjection)) {
return;

Check warning on line 45 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L45

Added line #L45 was not covered by tests
}
if (config('livewire-tables.inject_assets', true) === false && config('livewire-tables.inject_third_party_assets', true) === false) {
return;

Check warning on line 48 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L48

Added line #L48 was not covered by tests
}
if (config('livewire-tables.inject_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts && config('livewire-tables.inject_third_party_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) {
return;

Check warning on line 51 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L51

Added line #L51 was not covered by tests
} elseif (config('livewire-tables.inject_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) {
return;

Check warning on line 53 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L53

Added line #L53 was not covered by tests
} elseif (config('livewire-tables.inject_third_party_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) {
return;

Check warning on line 55 in src/Features/AutoInjectRappasoftAssets.php

View check run for this annotation

Codecov / codecov/patch

src/Features/AutoInjectRappasoftAssets.php#L55

Added line #L55 was not covered by tests
}
$html = $handled->response->getContent();

if (str($html)->contains('</html>')) {
Expand Down
3 changes: 1 addition & 2 deletions src/LaravelLivewireTablesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public function boot(): void
if (config('livewire-tables.inject_assets', true) === true) {

(new RappasoftFrontendAssets)->boot();
app('livewire')->componentHook(AutoInjectRappasoftAssets::class);
ComponentHookRegistry::boot();
}

}
Expand All @@ -63,6 +61,7 @@ public function register(): void
if (config('livewire-tables.inject_assets', true) === true) {

(new RappasoftFrontendAssets)->register();
ComponentHookRegistry::register(AutoInjectRappasoftAssets::class);
}
}
}

0 comments on commit fb476e4

Please sign in to comment.