Skip to content

9.9.0 #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2025
Merged

9.9.0 #626

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
Expand Down
56 changes: 50 additions & 6 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down Expand Up @@ -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');
}
}

/**
Expand Down
Loading