From 8036369653ade8ac77060f276ae7fb8f3394def9 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Tue, 5 Mar 2024 22:30:05 -0300 Subject: [PATCH] Fix L10 install (it also has a bootstrap/app.php) --- src/Commands/InstallCommand.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 54a478c..07ae465 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -86,19 +86,21 @@ private function installMiddlewareAfter($after, $name, $group = 'web') $middlewareGroups = Str::before(Str::after($httpKernel, '$middlewareGroups = ['), '];'); $middlewareGroup = Str::before(Str::after($middlewareGroups, "'$group' => ["), '],'); - if (! Str::contains($middlewareGroup, $name)) { - $modifiedMiddlewareGroup = str_replace( - $after.',', - $after.','.PHP_EOL.' '.$name.',', - $middlewareGroup, - ); - - file_put_contents(app_path('Http/Kernel.php'), str_replace( - $middlewareGroups, - str_replace($middlewareGroup, $modifiedMiddlewareGroup, $middlewareGroups), - $httpKernel - )); + if (str_contains($middlewareGroup, $name)) { + return; } + + $modifiedMiddlewareGroup = str_replace( + $after.',', + $after.','.PHP_EOL.' '.$name.',', + $middlewareGroup, + ); + + file_put_contents(app_path('Http/Kernel.php'), str_replace( + $middlewareGroups, + str_replace($middlewareGroup, $modifiedMiddlewareGroup, $middlewareGroups), + $httpKernel + )); } private function appendTailwindStylesToLayouts() @@ -119,10 +121,10 @@ private function existingLayoutFiles() private function installMiddleware(string $middleware) { - if (file_exists(base_path('bootstrap/app.php'))) { - $this->installMiddlewareToBootstrap($middleware); - } else { + if (file_exists(app_path('Http/Kernel.php'))) { $this->installMiddlewareAfter('SubstituteBindings::class', $middleware); + } else { + $this->installMiddlewareToBootstrap($middleware); } }