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') }} diff --git a/src/Commands/SetupCommand.php b/src/Commands/SetupCommand.php index 17dc318b0..ead6fb0f4 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,60 @@ 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'); + } } /**