|
1
|
|
|
<?php |
|
2
|
|
|
namespace keeko\tools\command; |
|
3
|
|
|
|
|
4
|
|
|
use keeko\tools\command\AbstractKeekoCommand; |
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Application; |
|
8
|
|
|
use Propel\Generator\Command\ModelBuildCommand; |
|
9
|
|
|
use keeko\tools\utils\NamespaceResolver; |
|
10
|
|
|
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; |
|
11
|
|
|
use gossi\codegen\model\PhpClass; |
|
12
|
|
|
use phootwork\lang\Text; |
|
13
|
|
|
use phootwork\file\File; |
|
14
|
|
|
|
|
15
|
|
|
class GenerateModelsCommand extends AbstractKeekoCommand { |
|
16
|
|
|
|
|
17
|
|
|
protected function configure() { |
|
18
|
|
|
$this |
|
19
|
|
|
->setName('generate:models') |
|
20
|
|
|
->setDescription('Generates propel models'); |
|
21
|
|
|
|
|
22
|
|
|
$this->configureGenerateOptions(); |
|
23
|
|
|
|
|
24
|
|
|
parent::configure(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
28
|
|
|
// run propel command |
|
29
|
|
|
$app = new Application(); |
|
30
|
|
|
$cmd = new ModelBuildCommand(); |
|
31
|
|
|
$app->add($cmd); |
|
32
|
|
|
|
|
33
|
|
|
$this->runCommand('model:build', [], $app); |
|
34
|
|
|
|
|
35
|
|
|
// cleanup |
|
36
|
|
|
$namespace = $this->modelService->getDatabase()->getNamespace(); |
|
37
|
|
|
$path = NamespaceResolver::getSourcePath($namespace, $this->package); |
|
38
|
|
|
|
|
39
|
|
|
$directory = new \RecursiveDirectoryIterator($this->project->getRootPath() . '/' . $path); |
|
40
|
|
|
$iterator = new \RecursiveIteratorIterator($directory); |
|
41
|
|
|
foreach ($iterator as $fileinfo) { |
|
42
|
|
|
if ($fileinfo->getExtension() == 'php') { |
|
43
|
|
|
$class = PhpClass::fromFile($fileinfo->getPathname()); |
|
44
|
|
|
$ns = $class->getNamespace(); |
|
45
|
|
|
if (!Text::create($ns)->startsWith($namespace)) { |
|
46
|
|
|
$file = new File($fileinfo->getPathname()); |
|
47
|
|
|
$file->delete(); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |