1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action\CreateDtosForAllEntitiesAction; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\PostProcessor\EntityFormatter; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class FinaliseBuildCommand extends AbstractCommand |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var CreateDtosForAllEntitiesAction |
15
|
|
|
*/ |
16
|
|
|
private $action; |
17
|
|
|
/** |
18
|
|
|
* @var EntityFormatter |
19
|
|
|
*/ |
20
|
|
|
private $entityFormatter; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
CreateDtosForAllEntitiesAction $action, |
24
|
|
|
EntityFormatter $entityFormatter, |
25
|
|
|
?string $name = null |
26
|
|
|
) { |
27
|
|
|
parent::__construct($name); |
28
|
|
|
$this->action = $action; |
29
|
|
|
$this->entityFormatter = $entityFormatter; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
33
|
|
|
{ |
34
|
|
|
try { |
35
|
|
|
$this->checkOptions($input); |
36
|
|
|
$output->writeln( |
37
|
|
|
'<comment>Starting generation of data transfer objects for all entities</comment>' |
38
|
|
|
); |
39
|
|
|
$this->action->setProjectRootNamespace($input->getOption(self::OPT_PROJECT_ROOT_NAMESPACE)) |
40
|
|
|
->setProjectRootDirectory($input->getOption(self::OPT_PROJECT_ROOT_PATH)) |
41
|
|
|
->run(); |
42
|
|
|
$output->writeln( |
43
|
|
|
'<comment>Formatting Entities</comment>' |
44
|
|
|
); |
45
|
|
|
$this->entityFormatter->setPathToProjectRoot($input->getOption(self::OPT_PROJECT_ROOT_PATH)) |
46
|
|
|
->run(); |
47
|
|
|
$output->writeln('<info>completed</info>'); |
48
|
|
|
} catch (\Exception $e) { |
49
|
|
|
throw new DoctrineStaticMetaException( |
50
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
51
|
|
|
$e->getCode(), |
52
|
|
|
$e |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @throws DoctrineStaticMetaException |
59
|
|
|
*/ |
60
|
|
|
protected function configure(): void |
61
|
|
|
{ |
62
|
|
|
try { |
63
|
|
|
$this |
64
|
|
|
->setName(AbstractCommand::COMMAND_PREFIX . 'finalise:build') |
65
|
|
|
->setDefinition( |
66
|
|
|
[ |
67
|
|
|
$this->getProjectRootPathOption(), |
68
|
|
|
$this->getProjectRootNamespaceOption(), |
69
|
|
|
] |
70
|
|
|
)->setDescription( |
71
|
|
|
'Generate or update all Data Transfer Objects for all Entities and perform other post processes' |
72
|
|
|
); |
73
|
|
|
} catch (\Exception $e) { |
74
|
|
|
throw new DoctrineStaticMetaException( |
75
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
76
|
|
|
$e->getCode(), |
77
|
|
|
$e |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|