From 97ebfe855536df61f22cbf828f5787dcdf0dd800 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 22 Apr 2025 17:21:33 +0300 Subject: [PATCH 1/3] feat: make sure to publish laravel 12 proper files --- src/Commands/SetupCommand.php | 54 +++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/src/Commands/SetupCommand.php b/src/Commands/SetupCommand.php index 17dc318b0..e1c1cc512 100644 --- a/src/Commands/SetupCommand.php +++ b/src/Commands/SetupCommand.php @@ -14,6 +14,9 @@ class SetupCommand extends Command public function handle() { + $this->comment('Installing Laravel API...'); + $this->call('install:api'); + $this->comment('Publishing Restify Service Provider...'); $this->callSilent('vendor:publish', ['--tag' => 'restify-provider']); @@ -44,19 +47,58 @@ public function handle() } /** - * Register the Restify service provider in the application configuration file. + * Register the Restify service provider in the bootstrap/providers.php file. * * @return void */ protected function registerRestifyServiceProvider() { $namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace()); + $providerClass = "{$namespace}\\Providers\\RestifyServiceProvider::class"; - file_put_contents(config_path('app.php'), str_replace( - "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL, - "{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." {$namespace}\Providers\RestifyServiceProvider::class,".PHP_EOL, - file_get_contents(config_path('app.php')) - )); + $providersPath = base_path('bootstrap/providers.php'); + + // Check if the providers.php file exists + if (!file_exists($providersPath)) { + $this->error('bootstrap/providers.php file not found. Make sure you are using Laravel 12.'); + return; + } + + $content = file_get_contents($providersPath); + + // Check if the provider is already registered + if (str_contains($content, $providerClass)) { + $this->line('RestifyServiceProvider already registered.'); + return; + } + + // Find the return statement + $pattern = '/return\s+(\[.*?\]);/s'; + if (preg_match($pattern, $content, $matches)) { + $providersArray = $matches[1]; + + // Remove the closing bracket + $providersArrayWithoutClosing = rtrim(trim($providersArray), ']'); + + // Add our provider and close the array + $newProvidersArray = $providersArrayWithoutClosing; + + // If the array is not empty and doesn't end with a comma, add a comma + if (!empty($providersArrayWithoutClosing) && !str_ends_with(trim($providersArrayWithoutClosing), ',')) { + $newProvidersArray .= ','; + } + + $newProvidersArray .= "\n {$providerClass},\n]"; + + // Replace the old array with the new one + $newContent = preg_replace($pattern, "return {$newProvidersArray};", $content); + + file_put_contents($providersPath, $newContent); + + $this->line('RestifyServiceProvider registered in bootstrap/providers.php'); + } else { + $this->error('Could not find the providers array in bootstrap/providers.php'); + } } /** From 00fe63291ba95768751b9e856fae165a40810da2 Mon Sep 17 00:00:00 2001 From: binaryk Date: Tue, 22 Apr 2025 14:21:57 +0000 Subject: [PATCH 2/3] Fix styling --- src/Commands/SetupCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Commands/SetupCommand.php b/src/Commands/SetupCommand.php index e1c1cc512..ead6fb0f4 100644 --- a/src/Commands/SetupCommand.php +++ b/src/Commands/SetupCommand.php @@ -59,8 +59,9 @@ protected function registerRestifyServiceProvider() $providersPath = base_path('bootstrap/providers.php'); // Check if the providers.php file exists - if (!file_exists($providersPath)) { + if (! file_exists($providersPath)) { $this->error('bootstrap/providers.php file not found. Make sure you are using Laravel 12.'); + return; } @@ -69,6 +70,7 @@ protected function registerRestifyServiceProvider() // Check if the provider is already registered if (str_contains($content, $providerClass)) { $this->line('RestifyServiceProvider already registered.'); + return; } @@ -84,7 +86,7 @@ protected function registerRestifyServiceProvider() $newProvidersArray = $providersArrayWithoutClosing; // If the array is not empty and doesn't end with a comma, add a comma - if (!empty($providersArrayWithoutClosing) && !str_ends_with(trim($providersArrayWithoutClosing), ',')) { + if (! empty($providersArrayWithoutClosing) && ! str_ends_with(trim($providersArrayWithoutClosing), ',')) { $newProvidersArray .= ','; } From f8d696d46180edd9bed4212d34a85f6c55de4fe0 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 22 Apr 2025 17:25:58 +0300 Subject: [PATCH 3/3] fix: wip --- .github/workflows/psalm.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 44ea6148c..6ec88bfdc 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -11,7 +11,7 @@ jobs: name: psalm runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -21,7 +21,7 @@ jobs: coverage: none - name: Cache composer dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor key: composer-${{ hashFiles('composer.lock') }}