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
|
1 |
|
public function __construct( |
24
|
|
|
EntityEmbeddableSetter $embeddableSetter, |
25
|
|
|
?string $name = null |
26
|
|
|
) { |
27
|
1 |
|
parent::__construct($name); |
28
|
1 |
|
$this->embeddableSetter = $embeddableSetter; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws DoctrineStaticMetaException |
33
|
|
|
*/ |
34
|
1 |
|
public function configure(): void |
35
|
|
|
{ |
36
|
|
|
try { |
37
|
1 |
|
$this->setName(AbstractCommand::COMMAND_PREFIX . 'set:embeddable') |
38
|
1 |
|
->setDefinition( |
39
|
|
|
[ |
40
|
1 |
|
new InputOption( |
41
|
1 |
|
self::OPT_ENTITY, |
42
|
1 |
|
self::OPT_ENTITY_SHORT, |
43
|
1 |
|
InputOption::VALUE_REQUIRED, |
44
|
1 |
|
'Entity Fully Qualified Name' |
45
|
|
|
), |
46
|
1 |
|
new InputOption( |
47
|
1 |
|
self::OPT_EMBEDDABLE, |
48
|
1 |
|
self::OPT_EMBEDDABLE_SHORT, |
49
|
1 |
|
InputOption::VALUE_REQUIRED, |
50
|
1 |
|
'Embeddable Trait Fully Qualified Name' |
51
|
|
|
), |
52
|
|
|
] |
53
|
1 |
|
)->setDescription( |
54
|
1 |
|
'Set an Entity as having an Embeddable by way of using the Embeddable Trait' |
55
|
|
|
); |
56
|
|
|
} catch (\Exception $e) { |
57
|
|
|
throw new DoctrineStaticMetaException( |
58
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
59
|
|
|
$e->getCode(), |
60
|
|
|
$e |
61
|
|
|
); |
62
|
|
|
} |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param InputInterface $input |
67
|
|
|
* @param OutputInterface $output |
68
|
|
|
* |
69
|
|
|
* @return int|null|void |
70
|
|
|
* @throws DoctrineStaticMetaException |
71
|
|
|
*/ |
72
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
73
|
|
|
{ |
74
|
|
|
try { |
75
|
1 |
|
$output->writeln( |
76
|
|
|
'<comment>Setting Entity ' |
77
|
1 |
|
. $input->getOption(static::OPT_ENTITY) |
78
|
1 |
|
. ' has Embeddable ' . $input->getOption(static::OPT_EMBEDDABLE) |
79
|
1 |
|
. '</comment>' |
80
|
|
|
); |
81
|
1 |
|
$this->checkOptions($input); |
82
|
1 |
|
$this->embeddableSetter |
83
|
1 |
|
->setEntityHasEmbeddable( |
84
|
1 |
|
$input->getOption(static::OPT_ENTITY), |
85
|
1 |
|
$input->getOption(static::OPT_EMBEDDABLE) |
86
|
|
|
); |
87
|
1 |
|
$output->writeln('<info>completed</info>'); |
88
|
|
|
} catch (\Exception $e) { |
89
|
|
|
throw new DoctrineStaticMetaException( |
90
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
91
|
|
|
$e->getCode(), |
92
|
|
|
$e |
93
|
|
|
); |
94
|
|
|
} |
95
|
1 |
|
} |
96
|
|
|
} |
97
|
|
|
|