1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action\CreateEmbeddableAction; |
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 GenerateEmbeddableSkeletonCommand extends AbstractCommand |
12
|
|
|
{ |
13
|
|
|
public const OPT_NEW_EMBEDDABLE_CATEGORY_NAME = 'catname'; |
14
|
|
|
public const OPT_NEW_EMBEDDABLE_CATEGORY_NAME_SHORT = 'm'; |
15
|
|
|
|
16
|
|
|
public const OPT_NEW_EMBEDDABLE_NAME = 'name'; |
17
|
|
|
public const OPT_NEW_EMBEDDABLE_NAME_SHORT = 'b'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var CreateEmbeddableAction |
21
|
|
|
*/ |
22
|
|
|
private $action; |
23
|
|
|
|
24
|
|
|
public function __construct( |
25
|
|
|
CreateEmbeddableAction $action, |
26
|
|
|
?string $name = null |
27
|
|
|
) { |
28
|
|
|
parent::__construct($name); |
29
|
|
|
$this->action = $action; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param InputInterface $input |
34
|
|
|
* @param OutputInterface $output |
35
|
|
|
* |
36
|
|
|
* @return int|null|void |
37
|
|
|
* @throws DoctrineStaticMetaException |
38
|
|
|
*/ |
39
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
|
|
try { |
42
|
|
|
$output->writeln( |
43
|
|
|
'<comment>Generating new Embeddable ' |
44
|
|
|
. $input->getOption(static::OPT_NEW_EMBEDDABLE_CATEGORY_NAME) . '\\' . |
45
|
|
|
$input->getOption(static::OPT_NEW_EMBEDDABLE_NAME) |
46
|
|
|
. '</comment>' |
47
|
|
|
); |
48
|
|
|
$this->checkOptions($input); |
49
|
|
|
$this->action |
50
|
|
|
->setProjectRootDirectory($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH)) |
51
|
|
|
->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE)) |
52
|
|
|
->setCatName($input->getOption(static::OPT_NEW_EMBEDDABLE_CATEGORY_NAME)) |
53
|
|
|
->setName($input->getOption(static::OPT_NEW_EMBEDDABLE_NAME)) |
54
|
|
|
->run(); |
55
|
|
|
$output->writeln('<info>completed</info>'); |
56
|
|
|
} catch (\Exception $e) { |
57
|
|
|
throw new DoctrineStaticMetaException( |
58
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
59
|
|
|
$e->getCode(), |
60
|
|
|
$e |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws DoctrineStaticMetaException |
67
|
|
|
*/ |
68
|
|
|
protected function configure(): void |
69
|
|
|
{ |
70
|
|
|
try { |
71
|
|
|
$this |
72
|
|
|
->setName(AbstractCommand::COMMAND_PREFIX . 'generate:skeleton-embeddable') |
73
|
|
|
->setDefinition( |
74
|
|
|
[ |
75
|
|
|
new InputOption( |
76
|
|
|
self::OPT_NEW_EMBEDDABLE_CATEGORY_NAME, |
77
|
|
|
self::OPT_NEW_EMBEDDABLE_CATEGORY_NAME_SHORT, |
78
|
|
|
InputOption::VALUE_REQUIRED, |
79
|
|
|
'The category name for this embeddable, eg Financial' |
80
|
|
|
), |
81
|
|
|
new InputOption( |
82
|
|
|
self::OPT_NEW_EMBEDDABLE_NAME, |
83
|
|
|
self::OPT_NEW_EMBEDDABLE_NAME_SHORT, |
84
|
|
|
InputOption::VALUE_REQUIRED, |
85
|
|
|
'The name for this embeddable, eg Price' |
86
|
|
|
), |
87
|
|
|
$this->getProjectRootPathOption(), |
88
|
|
|
$this->getProjectRootNamespaceOption(), |
89
|
|
|
] |
90
|
|
|
)->setDescription( |
91
|
|
|
'Generate an Embeddable skeleton ready to be customised' |
92
|
|
|
); |
93
|
|
|
} catch (\Exception $e) { |
94
|
|
|
throw new DoctrineStaticMetaException( |
95
|
|
|
'Exception in ' . __METHOD__ . ': ' . $e->getMessage(), |
96
|
|
|
$e->getCode(), |
97
|
|
|
$e |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|