|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Embeddable\EntityEmbeddableSetter; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class SetEmbeddableCommand extends AbstractCommand |
|
12
|
|
|
{ |
|
13
|
|
|
public const OPT_ENTITY = 'entity'; |
|
14
|
|
|
public const OPT_ENTITY_SHORT = 'o'; |
|
15
|
|
|
|
|
16
|
|
|
public const OPT_EMBEDDABLE = 'embeddable'; |
|
17
|
|
|
public const OPT_EMBEDDABLE_SHORT = 'b'; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var EntityEmbeddableSetter |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $embeddableSetter; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
EntityEmbeddableSetter $embeddableSetter, |
|
25
|
|
|
?string $name = null |
|
26
|
|
|
) { |
|
27
|
|
|
parent::__construct($name); |
|
28
|
|
|
$this->embeddableSetter = $embeddableSetter; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @throws DoctrineStaticMetaException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function configure(): void |
|
35
|
|
|
{ |
|
36
|
|
|
try { |
|
37
|
|
|
$this->setName(AbstractCommand::COMMAND_PREFIX . 'set:embeddable') |
|
38
|
|
|
->setDefinition( |
|
39
|
|
|
[ |
|
40
|
|
|
new InputOption( |
|
41
|
|
|
self::OPT_ENTITY, |
|
42
|
|
|
self::OPT_ENTITY_SHORT, |
|
43
|
|
|
InputOption::VALUE_REQUIRED, |
|
44
|
|
|
'Entity Fully Qualified Name' |
|
45
|
|
|
), |
|
46
|
|
|
new InputOption( |
|
47
|
|
|
self::OPT_EMBEDDABLE, |
|
48
|
|
|
self::OPT_EMBEDDABLE_SHORT, |
|
49
|
|
|
InputOption::VALUE_REQUIRED, |
|
50
|
|
|
'Embeddable Trait Fully Qualified Name' |
|
51
|
|
|
), |
|
52
|
|
|
$this->getProjectRootPathOption(), |
|
53
|
|
|
$this->getProjectRootNamespaceOption(), |
|
54
|
|
|
] |
|
55
|
|
|
)->setDescription( |
|
56
|
|
|
'Set an Entity as having an Embeddable by way of using the Embeddable Trait' |
|
57
|
|
|
); |
|
58
|
|
|
} catch (\Exception $e) { |
|
59
|
|
|
throw new DoctrineStaticMetaException( |
|
60
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
|
61
|
|
|
$e->getCode(), |
|
62
|
|
|
$e |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param InputInterface $input |
|
69
|
|
|
* @param OutputInterface $output |
|
70
|
|
|
* |
|
71
|
|
|
* @return int|null|void |
|
72
|
|
|
* @throws DoctrineStaticMetaException |
|
73
|
|
|
*/ |
|
74
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
75
|
|
|
{ |
|
76
|
|
|
try { |
|
77
|
|
|
$output->writeln( |
|
78
|
|
|
'<comment>Setting Entity ' |
|
79
|
|
|
. $input->getOption(static::OPT_ENTITY) |
|
80
|
|
|
. ' has Embeddable ' . $input->getOption(static::OPT_EMBEDDABLE) |
|
81
|
|
|
. '</comment>' |
|
82
|
|
|
); |
|
83
|
|
|
$this->checkOptions($input); |
|
84
|
|
|
$this->embeddableSetter |
|
85
|
|
|
->setPathToProjectRoot($input->getOption(self::OPT_PROJECT_ROOT_PATH)) |
|
86
|
|
|
->setProjectRootNamespace($input->getOption(self::OPT_PROJECT_ROOT_NAMESPACE)) |
|
87
|
|
|
->setEntityHasEmbeddable( |
|
88
|
|
|
$input->getOption(static::OPT_ENTITY), |
|
89
|
|
|
$input->getOption(static::OPT_EMBEDDABLE) |
|
90
|
|
|
); |
|
91
|
|
|
$output->writeln('<info>completed</info>'); |
|
92
|
|
|
} catch (\Exception $e) { |
|
93
|
|
|
throw new DoctrineStaticMetaException( |
|
94
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
|
95
|
|
|
$e->getCode(), |
|
96
|
|
|
$e |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|