From d75007dfe91348bc5d9fefec65dfbe35e7302ad7 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sun, 23 May 2021 15:17:42 +0200 Subject: [PATCH] Make requested changes --- src/Commands/Component.php | 12 ------------ src/Commands/ComponentCommand.php | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 src/Commands/Component.php diff --git a/src/Commands/Component.php b/src/Commands/Component.php deleted file mode 100644 index f1c0db8..0000000 --- a/src/Commands/Component.php +++ /dev/null @@ -1,12 +0,0 @@ -argument('name')); - if (! is_dir($path = app_path('Airwire'))) { + if (!is_dir($path = app_path('Airwire'))) { mkdir($path); } @@ -33,7 +33,26 @@ class ComponentCommand extends Command } PHP); - Component::register($name); - $this->line("✨ Component app/Airwire/{$name}.php has been created and registered!\n"); + $this->register($name); + } + + protected function register($name) + { + try { + $path = app_path('Providers/AppServiceProvider.php'); + + $snake = Str::snake($name); + + file_put_contents($path, str_replace( + "function boot()\n {", + "function boot()\n {\n \Airwire\Airwire::component('{$snake}', {$name}::class);", + file_get_contents($path) + )); + + $this->line("✨ Component app/Airwire/{$name}.php has been created and registered!"); + } catch (Exception $exception) + { + $this->error('The component could not be registered. Please check your app/Providers/AppServiceProvider.php'); + } } }