1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Pomm's Cli package. |
4
|
|
|
* |
5
|
|
|
* (c) 2014 - 2015 Grégoire HUBERT <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace PommProject\Cli\Command; |
11
|
|
|
|
12
|
|
|
use PommProject\Foundation\ParameterHolder; |
13
|
|
|
use PommProject\ModelManager\Generator\EntityGenerator; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* GenerateEntity |
21
|
|
|
* |
22
|
|
|
* Entity generation command. |
23
|
|
|
* |
24
|
|
|
* @package Cli |
25
|
|
|
* @copyright 2014 - 2015 Grégoire HUBERT |
26
|
|
|
* @author Grégoire HUBERT |
27
|
|
|
* @license X11 {@link http://opensource.org/licenses/mit-license.php} |
28
|
|
|
* @see PommAwareCommand |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
class GenerateEntity extends RelationAwareCommand |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* configure |
34
|
|
|
* |
35
|
|
|
* @see Command |
36
|
|
|
*/ |
37
|
|
|
protected function configure() |
38
|
|
|
{ |
39
|
|
|
$this |
40
|
|
|
->setName('pomm:generate:entity') |
41
|
|
|
->setDescription('Generate an Entity class.') |
42
|
|
|
->setHelp(<<<HELP |
43
|
|
|
This command generates an empty FlexibleEntity class in the given directory with the given namespace. By default, it creates a tree structure in the following format: ConfigName/NameSchema. |
44
|
|
|
|
45
|
|
|
In order to comply with the project’s autoloading rules, it is possible to prefix this directory structure and / or namespace: |
46
|
|
|
|
47
|
|
|
<info>pomm:generate:entity -d sources/lib/Model -a 'Vendor\Project\Model' --psr4 builder_name</info> |
48
|
|
|
|
49
|
|
|
HELP |
50
|
|
|
) |
51
|
|
|
; |
52
|
|
|
parent::configure(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* configureOptionals |
57
|
|
|
* |
58
|
|
|
* @see PommAwareCommand |
59
|
|
|
*/ |
60
|
|
|
protected function configureOptionals() |
61
|
|
|
{ |
62
|
|
|
parent::configureOptionals() |
63
|
|
|
->addOption( |
64
|
|
|
'force', |
65
|
|
|
null, |
66
|
|
|
InputOption::VALUE_NONE, |
67
|
|
|
'Force overwriting an existing file.' |
68
|
|
|
) |
69
|
|
|
->addOption( |
70
|
|
|
'psr4', |
71
|
|
|
null, |
72
|
|
|
InputOption::VALUE_NONE, |
73
|
|
|
'Use PSR4 structure.' |
74
|
|
|
) |
75
|
|
|
->addOption( |
76
|
|
|
'path-pattern', |
77
|
|
|
null, |
78
|
|
|
InputOption::VALUE_REQUIRED, |
79
|
|
|
'Use a different directory pattern when generating classes.', |
80
|
|
|
'{session}/{schema}Schema' |
81
|
|
|
) |
82
|
|
|
; |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* execute |
89
|
|
|
* |
90
|
|
|
* @see Command |
91
|
|
|
*/ |
92
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
93
|
|
|
{ |
94
|
|
|
parent::execute($input, $output); |
95
|
|
|
|
96
|
|
|
$session = $this->mustBeModelManagerSession($this->getSession()); |
97
|
|
|
|
98
|
|
|
$this->pathFile = $this->getPathFile( |
99
|
|
|
$input->getArgument('config-name'), |
|
|
|
|
100
|
|
|
$this->relation, |
|
|
|
|
101
|
|
|
'', |
102
|
|
|
'', |
103
|
|
|
$input->getOption('psr4'), |
104
|
|
|
$input->getOption('path-pattern') |
105
|
|
|
); |
106
|
|
|
$this->namespace = $this->getNamespace($input->getArgument('config-name'), null, $input->getOption('path-pattern')); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$this->updateOutput( |
109
|
|
|
$output, |
110
|
|
|
(new EntityGenerator( |
111
|
|
|
$session, |
112
|
|
|
$this->schema, |
|
|
|
|
113
|
|
|
$this->relation, |
|
|
|
|
114
|
|
|
$this->pathFile, |
115
|
|
|
$this->namespace, |
116
|
|
|
$this->flexible_container |
117
|
|
|
))->generate(new ParameterHolder(['force' => $input->getOption('force')])) |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
return 0; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.