|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Lej\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class CreateEntityCommand extends AbstractCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* {@inheritdoc} |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function configure() |
|
17
|
|
|
{ |
|
18
|
|
|
$this |
|
19
|
|
|
->setName('lej-ddd:create-entity') |
|
20
|
|
|
->setDescription('Creates an entity.') |
|
21
|
|
|
->addArgument('domain', InputArgument::REQUIRED, 'The name of the domain.') |
|
22
|
|
|
->addArgument('context', InputArgument::REQUIRED, 'The name of the context.') |
|
23
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'The name of the entity.'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
30
|
|
|
{ |
|
31
|
|
|
$twig = $this->twig(); |
|
32
|
|
|
|
|
33
|
|
|
$path = $this->modelPath($input->getArgument('domain'), $input->getArgument('context')); |
|
34
|
|
|
$namespace = $this->modelNamespace($input->getArgument('domain'), $input->getArgument('context')); |
|
35
|
|
|
@mkdir($path, 0755, true); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$entityClassName = $input->getArgument('name'); |
|
38
|
|
|
$idClassName = $entityClassName . 'Id'; |
|
39
|
|
|
|
|
40
|
|
|
$entity = $twig->render('entity.php.twig', [ |
|
41
|
|
|
'namespace' => $namespace, |
|
42
|
|
|
'entityClassName' => $entityClassName, |
|
43
|
|
|
'idClassName' => $idClassName |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
$id = $twig->render('uuid_id.php.twig', [ |
|
47
|
|
|
'namespace' => $namespace, |
|
48
|
|
|
'idClassName' => $idClassName |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
|
|
file_put_contents($path . '/' . $entityClassName . '.php', $entity); |
|
52
|
|
|
file_put_contents($path . '/' . $idClassName . '.php', $id); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: