Skip to content

Commit 91a688c

Browse files
authored
9.9.0 (#626)
* feat: make sure to publish laravel 12 proper files * Fix styling * fix: wip --------- Co-authored-by: binaryk <[email protected]>
1 parent d0a670c commit 91a688c

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

.github/workflows/psalm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: psalm
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515

1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
@@ -21,7 +21,7 @@ jobs:
2121
coverage: none
2222

2323
- name: Cache composer dependencies
24-
uses: actions/cache@v2
24+
uses: actions/cache@v4
2525
with:
2626
path: vendor
2727
key: composer-${{ hashFiles('composer.lock') }}

src/Commands/SetupCommand.php

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class SetupCommand extends Command
1414

1515
public function handle()
1616
{
17+
$this->comment('Installing Laravel API...');
18+
$this->call('install:api');
19+
1720
$this->comment('Publishing Restify Service Provider...');
1821
$this->callSilent('vendor:publish', ['--tag' => 'restify-provider']);
1922

@@ -44,19 +47,60 @@ public function handle()
4447
}
4548

4649
/**
47-
* Register the Restify service provider in the application configuration file.
50+
* Register the Restify service provider in the bootstrap/providers.php file.
4851
*
4952
* @return void
5053
*/
5154
protected function registerRestifyServiceProvider()
5255
{
5356
$namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace());
57+
$providerClass = "{$namespace}\\Providers\\RestifyServiceProvider::class";
5458

55-
file_put_contents(config_path('app.php'), str_replace(
56-
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL,
57-
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." {$namespace}\Providers\RestifyServiceProvider::class,".PHP_EOL,
58-
file_get_contents(config_path('app.php'))
59-
));
59+
$providersPath = base_path('bootstrap/providers.php');
60+
61+
// Check if the providers.php file exists
62+
if (! file_exists($providersPath)) {
63+
$this->error('bootstrap/providers.php file not found. Make sure you are using Laravel 12.');
64+
65+
return;
66+
}
67+
68+
$content = file_get_contents($providersPath);
69+
70+
// Check if the provider is already registered
71+
if (str_contains($content, $providerClass)) {
72+
$this->line('RestifyServiceProvider already registered.');
73+
74+
return;
75+
}
76+
77+
// Find the return statement
78+
$pattern = '/return\s+(\[.*?\]);/s';
79+
if (preg_match($pattern, $content, $matches)) {
80+
$providersArray = $matches[1];
81+
82+
// Remove the closing bracket
83+
$providersArrayWithoutClosing = rtrim(trim($providersArray), ']');
84+
85+
// Add our provider and close the array
86+
$newProvidersArray = $providersArrayWithoutClosing;
87+
88+
// If the array is not empty and doesn't end with a comma, add a comma
89+
if (! empty($providersArrayWithoutClosing) && ! str_ends_with(trim($providersArrayWithoutClosing), ',')) {
90+
$newProvidersArray .= ',';
91+
}
92+
93+
$newProvidersArray .= "\n {$providerClass},\n]";
94+
95+
// Replace the old array with the new one
96+
$newContent = preg_replace($pattern, "return {$newProvidersArray};", $content);
97+
98+
file_put_contents($providersPath, $newContent);
99+
100+
$this->line('RestifyServiceProvider registered in bootstrap/providers.php');
101+
} else {
102+
$this->error('Could not find the providers array in bootstrap/providers.php');
103+
}
60104
}
61105

62106
/**

0 commit comments

Comments
 (0)