1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of FlexPHP. |
4
|
|
|
* |
5
|
|
|
* (c) Freddie Gar <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace FlexPHP\Generator\Domain\UseCases; |
11
|
|
|
|
12
|
|
|
use FlexPHP\Generator\Domain\Builders\Command\CommandBuilder; |
13
|
|
|
use FlexPHP\Generator\Domain\Builders\Inflector; |
14
|
|
|
use FlexPHP\Generator\Domain\Messages\Requests\CreateCommandFileRequest; |
15
|
|
|
use FlexPHP\Generator\Domain\Messages\Responses\CreateCommandFileResponse; |
16
|
|
|
use FlexPHP\Generator\Domain\Writers\PhpWriter; |
17
|
|
|
|
18
|
|
|
final class CreateCommandFileUseCase |
19
|
|
|
{ |
20
|
|
|
public function execute(CreateCommandFileRequest $request): CreateCommandFileResponse |
21
|
|
|
{ |
22
|
|
|
$files = []; |
23
|
|
|
$inflector = new Inflector(); |
24
|
|
|
$entity = $inflector->entity($request->schema->name()); |
25
|
|
|
|
26
|
|
|
$path = \sprintf('%1$s/../../tmp/skeleton/src/Command/%2$s', __DIR__, $entity); |
27
|
|
|
$actions = \array_diff($request->actions, ['login', 'filter']); |
28
|
|
|
|
29
|
|
|
foreach ($actions as $action) { |
30
|
|
|
$builder = new CommandBuilder($request->schema, $action); |
31
|
|
|
$filename = $inflector->pascalAction($action) . $entity . 'Command'; |
32
|
|
|
|
33
|
|
|
$writer = new PhpWriter($builder->build(), $filename, $path); |
34
|
|
|
$files[] = $writer->save(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return new CreateCommandFileResponse($files); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|