1
0
Fork 0
mirror of https://github.com/archtechx/airwire.git synced 2025-12-12 02:34:04 +00:00

Make requested changes

This commit is contained in:
lukinovec 2021-05-23 15:17:42 +02:00
parent de1c1faaa7
commit d75007dfe9
2 changed files with 22 additions and 15 deletions

View file

@ -1,12 +0,0 @@
<?php
namespace Airwire\Commands;
use Illuminate\Support\Str;
class Component {
public static function register(string $name)
{
$service_provider = base_path() . "\app\Providers\AppServiceProvider.php";
file_put_contents($service_provider, preg_replace('/register[(][)][\s\S].*/', "register() {\n\t\tAirwire::component('" . Str::snake($name) . "', {$name}::class);", file_get_contents($service_provider)));
}
}

View file

@ -33,7 +33,26 @@ class ComponentCommand extends Command
} }
PHP); PHP);
Component::register($name); $this->register($name);
$this->line("✨ Component app/Airwire/{$name}.php has been created and registered!\n"); }
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');
}
} }
} }