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:
parent
de1c1faaa7
commit
d75007dfe9
2 changed files with 22 additions and 15 deletions
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ class ComponentCommand extends Command
|
|||
{
|
||||
$name = Str::studly($this->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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue