From 330e68bbe4b28140a55806bea54054781286ff6d Mon Sep 17 00:00:00 2001 From: thejmitchener Date: Wed, 12 Jun 2024 15:26:48 -0400 Subject: [PATCH 1/4] Added functionality to update a specific route in the web.php file if it exists, otherwise display an error message. This change was made to ensure that the specified route is updated correctly during the installation process. --- src/Commands/NavigationInstallCommand.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Commands/NavigationInstallCommand.php b/src/Commands/NavigationInstallCommand.php index 32efd38..4f83f22 100644 --- a/src/Commands/NavigationInstallCommand.php +++ b/src/Commands/NavigationInstallCommand.php @@ -32,6 +32,24 @@ public function handle() $this->runShellCommand($requireCommand); + $filePath = base_path('routes/web.php'); + $search = "Route::get('/', function () {\n return view('welcome');\n});"; + $replace = "Route::get('/', function () {\n return view('welcome');\n})->name('welcome');"; + + if (file_exists($filePath)) { + $fileContents = file_get_contents($filePath); + + if (strpos($fileContents, $search) !== false) { + $fileContents = str_replace($search, $replace, $fileContents); + file_put_contents($filePath, $fileContents); + $this->info('Route updated successfully.'); + } else { + $this->info('The specified route was not found in the file.'); + } + } else { + $this->error('The web.php file does not exist.'); + } + $this->info('Packages installed successfully.'); } From 6d3010536003020abef8f0192bef84454d948101 Mon Sep 17 00:00:00 2001 From: thejmitchener Date: Wed, 12 Jun 2024 15:33:13 -0400 Subject: [PATCH 2/4] Refactored NavigationInstallCommand.php to use Laravel's File facade for file operations and simplified the logic for updating a route in the web.php file. The changes were made to improve code readability and maintainability. --- src/Commands/NavigationInstallCommand.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Commands/NavigationInstallCommand.php b/src/Commands/NavigationInstallCommand.php index 4f83f22..7630d3c 100644 --- a/src/Commands/NavigationInstallCommand.php +++ b/src/Commands/NavigationInstallCommand.php @@ -5,6 +5,7 @@ use Illuminate\Console\Command; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; +use Illuminate\Support\Facades\File; class NavigationInstallCommand extends Command { @@ -36,19 +37,13 @@ public function handle() $search = "Route::get('/', function () {\n return view('welcome');\n});"; $replace = "Route::get('/', function () {\n return view('welcome');\n})->name('welcome');"; - if (file_exists($filePath)) { - $fileContents = file_get_contents($filePath); - - if (strpos($fileContents, $search) !== false) { - $fileContents = str_replace($search, $replace, $fileContents); - file_put_contents($filePath, $fileContents); - $this->info('Route updated successfully.'); - } else { - $this->info('The specified route was not found in the file.'); - } - } else { - $this->error('The web.php file does not exist.'); - } + $fileContents = File::get($filePath); + + $updatedContents = str_replace($search, $replace, $fileContents); + + File::put($filePath, $updatedContents); + + $this->info('Route updated successfully.'); $this->info('Packages installed successfully.'); } From f43fcb4f985c94ed2462a0849c6af57e7c82363e Mon Sep 17 00:00:00 2001 From: thejmitchener Date: Wed, 12 Jun 2024 19:33:34 +0000 Subject: [PATCH 3/4] Fix styling --- src/Commands/NavigationInstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/NavigationInstallCommand.php b/src/Commands/NavigationInstallCommand.php index 7630d3c..780e4e3 100644 --- a/src/Commands/NavigationInstallCommand.php +++ b/src/Commands/NavigationInstallCommand.php @@ -3,9 +3,9 @@ namespace Fuelviews\Navigation\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Facades\File; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; -use Illuminate\Support\Facades\File; class NavigationInstallCommand extends Command { From 0a99cc4f237bf4d419dc1d86a0fee0690dea4331 Mon Sep 17 00:00:00 2001 From: thejmitchener Date: Wed, 12 Jun 2024 15:33:59 -0400 Subject: [PATCH 4/4] Refactor NavigationInstallCommand.php to remove unnecessary comments and improve code readability. --- src/Commands/NavigationInstallCommand.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Commands/NavigationInstallCommand.php b/src/Commands/NavigationInstallCommand.php index 780e4e3..f33dacd 100644 --- a/src/Commands/NavigationInstallCommand.php +++ b/src/Commands/NavigationInstallCommand.php @@ -52,10 +52,8 @@ private function runShellCommand($command) { $process = Process::fromShellCommandline($command); - // Set the input to the process's standard input, allowing for interaction $process->setTty(Process::isTtySupported()); - // Run the process $process->run(function ($type, $buffer) { $this->output->write($buffer); });