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 Symfony\Component\Console\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* GenerateForSchema |
20
|
|
|
* |
21
|
|
|
* Generate a Structure, a model and an entity class if they do not already |
22
|
|
|
* exist (unless --force is specified). |
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 SchemaAwareCommand |
29
|
|
|
*/ |
30
|
|
|
class GenerateForSchema extends SchemaAwareCommand |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* configure |
34
|
|
|
* |
35
|
|
|
* @see Command |
36
|
|
|
*/ |
37
|
|
|
public function configure() |
38
|
|
|
{ |
39
|
|
|
$this |
40
|
|
|
->setName('pomm:generate:schema-all') |
41
|
|
|
->setDescription('Generate structure, model and entity file for all relations in a schema.') |
42
|
|
|
; |
43
|
|
|
parent::configure(); |
44
|
|
|
$this |
45
|
|
|
->addOption( |
46
|
|
|
'force', |
47
|
|
|
null, |
48
|
|
|
InputOption::VALUE_NONE, |
49
|
|
|
'Force overwriting existing files.' |
50
|
|
|
) |
51
|
|
|
->addOption( |
52
|
|
|
'psr4', |
53
|
|
|
null, |
54
|
|
|
InputOption::VALUE_NONE, |
55
|
|
|
'Use PSR4 structure.' |
56
|
|
|
) |
57
|
|
|
->addOption( |
58
|
|
|
'path-pattern', |
59
|
|
|
null, |
60
|
|
|
InputOption::VALUE_REQUIRED, |
61
|
|
|
'Use a different directory pattern when generating classes.', |
62
|
|
|
'{session}/{schema}Schema' |
63
|
|
|
) |
64
|
|
|
; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* execute |
69
|
|
|
* |
70
|
|
|
* @see Command |
71
|
|
|
*/ |
72
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
73
|
|
|
{ |
74
|
|
|
parent::execute($input, $output); |
75
|
|
|
|
76
|
|
|
$session = $this->mustBeModelManagerSession($this->getSession()); |
77
|
|
|
|
78
|
|
|
$relations = $session->getInspector() |
79
|
|
|
->getSchemaRelations($this->fetchSchemaOid()); |
80
|
|
|
|
81
|
|
|
$output->writeln( |
82
|
|
|
sprintf( |
83
|
|
|
"Scanning schema '<fg=green>%s</fg=green>'.", |
84
|
|
|
$this->schema |
85
|
|
|
) |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
if ($relations->isEmpty()) { |
89
|
|
|
$output->writeln("<bg=yellow>No relations found.</bg=yellow>"); |
90
|
|
|
} else { |
91
|
|
|
foreach ($relations as $relation_info) { |
92
|
|
|
$command = $this->getApplication()->find('pomm:generate:relation-all'); |
93
|
|
|
$arguments = [ |
94
|
|
|
'command' => 'pomm:generate:relation-all', |
95
|
|
|
'config-name' => $this->config_name, |
96
|
|
|
'relation' => $relation_info['name'], |
97
|
|
|
'schema' => $this->schema, |
98
|
|
|
'--force' => $input->getOption('force'), |
99
|
|
|
'--bootstrap-file' => $input->getOption('bootstrap-file'), |
100
|
|
|
'--prefix-dir' => $input->getOption('prefix-dir'), |
101
|
|
|
'--prefix-ns' => $input->getOption('prefix-ns'), |
102
|
|
|
'--path-pattern' => $input->getOption('path-pattern'), |
103
|
|
|
'--flexible-container' => $input->getOption('flexible-container'), |
104
|
|
|
'--psr4' => $input->getOption('psr4') |
105
|
|
|
]; |
106
|
|
|
$command->run(new ArrayInput($arguments), $output); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return 0; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|