-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathAllModels.php
More file actions
156 lines (141 loc) · 5.1 KB
/
Copy pathAllModels.php
File metadata and controls
156 lines (141 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare(strict_types=1);
/**
* This file is part of the Phalcon Developer Tools.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Phalcon\DevTools\Commands\Builtin;
use Phalcon\Config\Config;
use Phalcon\Config\Adapter\Ini as ConfigIni;
use Phalcon\DevTools\Builder\Component\AllModels as AllModelsBuilder;
use Phalcon\DevTools\Builder\Exception\BuilderException;
use Phalcon\DevTools\Commands\Command;
use Phalcon\DevTools\Commands\CommandsException;
/**
* AllModels Command
*
* Create all models from a database
*/
class AllModels extends Command
{
/**
* {@inheritdoc}
*
* @return array
*/
public function getPossibleParams(): array
{
return [
'config=s' => 'Configuration file [optional]',
'schema=s' => 'Name of the schema. [optional]',
'namespace=s' => "Model's namespace [optional]",
'extends=s' => 'Models extends [optional]',
'force' => 'Force script to rewrite all the models [optional]',
'camelize' => 'Properties is in camelCase [optional]',
'get-set' => 'Attributes will be protected and have setters/getters [optional]',
'doc' => 'Helps to improve code completion on IDEs [optional]',
'relations' => 'Possible relations defined according to convention [optional]',
'fk' => 'Define any virtual foreign keys [optional]',
'directory=s' => 'Base path on which project will be created [optional]',
'output=s' => 'Folder where models are located [optional]',
'mapcolumn' => 'Get some code for map columns [optional]',
'abstract' => 'Abstract Model [optional]',
'annotate' => 'Annotate Attributes [optional]',
'help' => 'Shows this help [optional]',
];
}
/**
* {@inheritdoc}
*
* @param array $parameters
* @throws CommandsException
* @throws BuilderException
*/
public function run(array $parameters): void
{
if ($this->isReceivedOption('directory')) {
if (!$this->path->isAbsolutePath($this->getOption('directory'))) {
$this->path->appendRootPath($this->getOption('directory'));
} else {
$this->path->setRootPath($this->getOption('directory'));
}
}
if ($this->isReceivedOption('config')) {
if (!$this->path->isAbsolutePath($this->getOption('config'))) {
$configPath = $this->path->getRootPath() . $this->getOption('config');
} else {
$configPath = $this->getOption('config');
}
if (preg_match('/.*(:?\.ini)(?:\s)?$/i', $configPath)) {
$config = new ConfigIni($configPath);
} else {
$config = include $configPath;
if (is_array($config)) {
$config = new Config($config);
}
}
} else {
$config = $this->path->getConfig();
}
if (!$this->isReceivedOption('output')) {
if (!isset($config->application->modelsDir)) {
throw new CommandsException("Builder doesn't know where is the models directory.");
}
$modelsDir = rtrim($config->application->modelsDir, '\\/') . DIRECTORY_SEPARATOR;
} else {
$modelsDir = $this->getOption('output');
}
if (!$this->path->isAbsolutePath($modelsDir)) {
$modelsDir = $this->path->getRootPath($modelsDir);
}
$modelBuilder = new AllModelsBuilder([
'force' => $this->isReceivedOption('force'),
'config' => $config,
'schema' => $this->getOption('schema'),
'extends' => $this->getOption('extends'),
'namespace' => $this->getOption('namespace'),
'directory' => $this->getOption('directory'),
'foreignKeys' => $this->isReceivedOption('fk'),
'defineRelations' => $this->isReceivedOption('relations'),
'genSettersGetters' => $this->isReceivedOption('get-set'),
'genDocMethods' => $this->isReceivedOption('doc'),
'modelsDir' => $modelsDir,
'mapColumn' => $this->isReceivedOption('mapcolumn'),
'abstract' => $this->isReceivedOption('abstract'),
'camelize' => $this->isReceivedOption('camelize'),
'annotate' => $this->isReceivedOption('annotate'),
]);
$modelBuilder->build();
}
/**
* {@inheritdoc}
*
* @return array
*/
public function getCommands(): array
{
return ['all-models', 'create-all-models'];
}
/**
* {@inheritdoc}
*
* @return void
*/
public function getHelp(): void
{
$this->printParameters($this->getPossibleParams());
}
/**
* {@inheritdoc}
*
* @return integer
*/
public function getRequiredParams(): int
{
return 0;
}
}