|
@@ -18,152 +18,140 @@ public function __construct(Filesystem $files)
|
|
|
$this->files = $files;
|
|
$this->files = $files;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function handle()
|
|
|
|
|
|
|
+ public function handle(): void
|
|
|
{
|
|
{
|
|
|
- $name = $this->argument('name');
|
|
|
|
|
- $this->createModel($name);
|
|
|
|
|
- $this->createRepositoryInterface($name);
|
|
|
|
|
- $this->createRepository($name);
|
|
|
|
|
- $this->createService($name);
|
|
|
|
|
- $this->createController($name);
|
|
|
|
|
- $this->createDto($name);
|
|
|
|
|
- $this->createRequest($name);
|
|
|
|
|
- $this->createResource($name);
|
|
|
|
|
- $this->createCollection($name);
|
|
|
|
|
- $this->updateAppServiceProvider($name);
|
|
|
|
|
- $this->info('CRUD operations created successfully!');
|
|
|
|
|
|
|
+ $name = $this->argument(key: 'name');
|
|
|
|
|
+ $this->createModel(name: $name);
|
|
|
|
|
+ $this->createRepositoryInterface(name: $name);
|
|
|
|
|
+ $this->createRepository(name: $name);
|
|
|
|
|
+ $this->createService(name: $name);
|
|
|
|
|
+ $this->createController(name: $name);
|
|
|
|
|
+ $this->createDTO(name: $name);
|
|
|
|
|
+ $this->createRequest(name: $name);
|
|
|
|
|
+ $this->createResource(name: $name);
|
|
|
|
|
+ $this->updateAppServiceProvider(name: $name);
|
|
|
|
|
+ $this->info(string: 'CRUD operations created successfully!');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createModel($name)
|
|
|
|
|
|
|
+ protected function createModel($name): void
|
|
|
{
|
|
{
|
|
|
$modelTemplate = str_replace(
|
|
$modelTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Model')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'Model')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Models/{$name}.php", $modelTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Models/{$name}.php", contents: $modelTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createRepositoryInterface($name)
|
|
|
|
|
|
|
+ protected function createRepositoryInterface($name): void
|
|
|
{
|
|
{
|
|
|
$interfaceTemplate = str_replace(
|
|
$interfaceTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('RepositoryInterface')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'RepositoryInterface')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Repositories/{$name}RepositoryInterface.php", $interfaceTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Repositories/{$name}RepositoryInterface.php", contents: $interfaceTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createRepository($name)
|
|
|
|
|
|
|
+ protected function createRepository($name): void
|
|
|
{
|
|
{
|
|
|
$repositoryTemplate = str_replace(
|
|
$repositoryTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Repository')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'Repository')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Repositories/{$name}Repository.php", $repositoryTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Repositories/{$name}Repository.php", contents: $repositoryTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createService($name)
|
|
|
|
|
|
|
+ protected function createService($name): void
|
|
|
{
|
|
{
|
|
|
$serviceTemplate = str_replace(
|
|
$serviceTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Service')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'Service')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Services/{$name}Service.php", $serviceTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Services/{$name}Service.php", contents: $serviceTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createController($name)
|
|
|
|
|
|
|
+ protected function createController($name): void
|
|
|
{
|
|
{
|
|
|
$controllerTemplate = str_replace(
|
|
$controllerTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Controller')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'Controller')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Http/Controllers/{$name}Controller.php", $controllerTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Http/Controllers/{$name}Controller.php", contents: $controllerTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createDto($name)
|
|
|
|
|
|
|
+ protected function createDTO($name): void
|
|
|
{
|
|
{
|
|
|
$dtoTemplate = str_replace(
|
|
$dtoTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Dto')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'DTO')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/DataTransferObjects/{$name}Dto.php", $dtoTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/DTO/{$name}DTO.php", contents: $dtoTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createRequest($name)
|
|
|
|
|
|
|
+ protected function createRequest($name): void
|
|
|
{
|
|
{
|
|
|
$requestTemplate = str_replace(
|
|
$requestTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Request')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'Request')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Http/Requests/{$name}Request.php", $requestTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Http/Requests/{$name}Request.php", contents: $requestTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createResource($name)
|
|
|
|
|
|
|
+ protected function createResource($name): void
|
|
|
{
|
|
{
|
|
|
$resourceTemplate = str_replace(
|
|
$resourceTemplate = str_replace(
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Resource')
|
|
|
|
|
|
|
+ search: ['{{modelName}}'],
|
|
|
|
|
+ replace: [$name],
|
|
|
|
|
+ subject: $this->getStub(type: 'Resource')
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->put("app/Http/Resources/{$name}Resource.php", $resourceTemplate);
|
|
|
|
|
|
|
+ $this->put(path: "app/Http/Resources/{$name}Resource.php", contents: $resourceTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function createCollection($name)
|
|
|
|
|
|
|
+ protected function updateAppServiceProvider($name): void
|
|
|
{
|
|
{
|
|
|
- $collectionTemplate = str_replace(
|
|
|
|
|
- ['{{modelName}}'],
|
|
|
|
|
- [$name],
|
|
|
|
|
- $this->getStub('Collection')
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- $this->put("app/Http/Resources/{$name}Collection.php", $collectionTemplate);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- protected function updateAppServiceProvider($name)
|
|
|
|
|
- {
|
|
|
|
|
- $providerPath = app_path('Providers/AppServiceProvider.php');
|
|
|
|
|
- $content = $this->files->get($providerPath);
|
|
|
|
|
|
|
+ $providerPath = app_path(path: 'Providers/AppServiceProvider.php');
|
|
|
|
|
+ $content = $this->files->get(path: $providerPath);
|
|
|
|
|
|
|
|
// Add binding
|
|
// Add binding
|
|
|
$binding = " {$name}RepositoryInterface::class => {$name}Repository::class,";
|
|
$binding = " {$name}RepositoryInterface::class => {$name}Repository::class,";
|
|
|
$content = preg_replace(
|
|
$content = preg_replace(
|
|
|
- '/(public \$bindings = \[)/',
|
|
|
|
|
- "$1\n$binding",
|
|
|
|
|
- $content
|
|
|
|
|
|
|
+ pattern: '/(public \$bindings = \[)/',
|
|
|
|
|
+ replacement: "$1\n$binding",
|
|
|
|
|
+ subject: $content
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Add use statement
|
|
// Add use statement
|
|
|
$useStatement = "use App\Repositories\\{$name}RepositoryInterface;\nuse App\Repositories\\{$name}Repository;";
|
|
$useStatement = "use App\Repositories\\{$name}RepositoryInterface;\nuse App\Repositories\\{$name}Repository;";
|
|
|
$content = preg_replace(
|
|
$content = preg_replace(
|
|
|
- '/(use Illuminate\\\Support\\\ServiceProvider;)/',
|
|
|
|
|
- "$1\n\n{$useStatement}",
|
|
|
|
|
- $content
|
|
|
|
|
|
|
+ pattern: '/(use Illuminate\\\Support\\\ServiceProvider;)/',
|
|
|
|
|
+ replacement: "$1\n\n{$useStatement}",
|
|
|
|
|
+ subject: $content
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- $this->files->put($providerPath, $content);
|
|
|
|
|
|
|
+ $this->files->put(path: $providerPath, contents: $content);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function getStub($type)
|
|
|
|
|
|
|
+ protected function getStub($type): string
|
|
|
{
|
|
{
|
|
|
- return $this->files->get(storage_path("stubs/{$type}.stub"));
|
|
|
|
|
|
|
+ return $this->files->get(path: storage_path(path: "stubs/{$type}.stub"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function put($path, $contents)
|
|
|
|
|
|
|
+ protected function put($path, $contents): void
|
|
|
{
|
|
{
|
|
|
- $this->files->put($path, $contents);
|
|
|
|
|
|
|
+ $this->files->put(path: $path, contents: $contents);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|