Skip to content

Commit a442d3f

Browse files
committed
refactor(PluginManager): remove unused lifecycle hook calls
refactor(MakePluginCommand): simplify directory creation logging fix(MakePluginCommand): correct route parameter syntax feat(MakePluginCommand): add route file creation after controller refactor(MakePluginCommand): move route creation logic to controller method
1 parent 8649765 commit a442d3f

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/Commands/MakePluginCommand.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ protected function createPluginDirectories(string $pluginPath): void
9393
];
9494

9595
foreach ($directories as $directory) {
96-
!File::exists($directory) && File::makeDirectory($directory, 0755, true);
97-
98-
$this->line('Created directory: ' . basename($directory));
96+
!File::exists($directory) && File::makeDirectory($directory, 0755, true) && $this->line('Created directory: ' . basename($directory));
9997
}
10098
}
10199

@@ -200,6 +198,7 @@ protected function createControllerFile(string $pluginPath, string $pluginName,
200198
}
201199

202200
$filePath = $pluginPath . '/Controllers/' . $fileName;
201+
203202
if (File::exists($filePath)) {
204203
$this->warn("Controller file '{$fileName}' already exists in plugin '{$pluginName}'. Skipping...");
205204
return;
@@ -287,7 +286,12 @@ public function index()
287286
}
288287

289288
File::put($pluginPath . '/Controllers/' . $fileName, $content);
289+
290290
$this->line("Created: {$fileName}");
291+
292+
if ($this->option('route')) {
293+
$this->createRouteFile($pluginPath, $pluginName, $controllerName);
294+
}
291295
}
292296

293297
protected function createServiceFile(string $pluginPath, string $pluginName): void
@@ -660,7 +664,7 @@ public function color(): string
660664
$this->line("Created enum: {$filePath}");
661665
}
662666

663-
protected function createConcernFile(string $pluginPath, string $pluginName,string $trait): void
667+
protected function createConcernFile(string $pluginPath, string $pluginName, string $trait): void
664668
{
665669
$filePath = "{$pluginPath}/Concerns/{$trait}.php";
666670
$traitName = ucfirst($trait);
@@ -733,11 +737,6 @@ protected function createAdditionalComponents(string $pluginPath, string $plugin
733737
$this->createViewFile($pluginPath, $pluginName, $viewType, $this->option('view'));
734738
}
735739

736-
if ($this->option('route')) {
737-
$controllerName = $this->option('controller') ?? $pluginName;
738-
$this->createRouteFile($pluginPath, $pluginName, $controllerName);
739-
}
740-
741740
if ($this->option('enum')) {
742741
$this->createEnumFile($pluginPath, $pluginName, $this->option('enum'));
743742
}
@@ -755,15 +754,20 @@ protected function createRouteFile(string $pluginPath, string $pluginName, ?stri
755754
$filePath = $pluginPath . '/' . $fileName;
756755

757756
$pluginNameLower = strtolower($pluginName);
758-
$controllerClass = $controllerName . 'Controller';
757+
758+
if (str_ends_with($controllerName, 'Controller')) {
759+
$controllerClass = Str::studly($controllerName);
760+
} else {
761+
$controllerClass = Str::studly("{$controllerName}Controller");
762+
}
759763

760764
$newRoutes = "
761765
Route::controller({$controllerClass}::class)->group(function () {
762766
Route::get('/', 'index')->name('{$pluginNameLower}.index');
763767
Route::post('/', 'store')->name('{$pluginNameLower}.store');
764-
Route::get('/{{id}}', 'show')->name('{$pluginNameLower}.show');
765-
Route::put('/{{id}}', 'update')->name('{$pluginNameLower}.update');
766-
Route::delete('/{{id}}', 'destroy')->name('{$pluginNameLower}.destroy');
768+
Route::get('/{id}', 'show')->name('{$pluginNameLower}.show');
769+
Route::put('/{id}', 'update')->name('{$pluginNameLower}.update');
770+
Route::delete('/{id}', 'destroy')->name('{$pluginNameLower}.destroy');
767771
});";
768772

769773
if (File::exists($filePath)) {

src/PluginManager.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function register(): void
2929
$this->registerPluginConfigs();
3030
$this->registerPluginServices();
3131
$this->registerPluginProviders();
32-
$this->callLifecycleHook('register');
3332
}
3433

3534
public function boot(): void
@@ -39,7 +38,6 @@ public function boot(): void
3938
$this->registerPluginControllers();
4039
$this->registerPluginCommands();
4140
$this->registerPluginEvents();
42-
$this->callLifecycleHook('boot');
4341
}
4442

4543
protected function callLifecycleHook(string $method): void

0 commit comments

Comments
 (0)