This repository has been archived by the owner on Sep 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.php
executable file
·101 lines (83 loc) · 4.1 KB
/
console.php
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
#!/usr/bin/env php
<?php
//Include the namespaces of the components we plan to use
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Cnerta\EntityGeneratorBundle\Engine\PowerAmcMPDParserEnginev2 as PowerAmcMPDParserEngine;
use Cnerta\EntityGeneratorBundle\Engine\EntityGenerator;
use Cnerta\EntityGeneratorBundle\TwigExtentions\MyTwigExtension;
//Bootstrap our Silex application
require_once __DIR__.'/vendor/autoload.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/src/Cnerta/EntityGeneratorBundle/Resources/views',
));
$app['twig']->addExtension(new MyTwigExtension());
//Instantiate our Console application
$console = new Application('entity generator', '0.1');
//Register a command to run from the command line
//Our command will be started with "./console.php sync"
$console->register('entity:generator')
->setDefinition(array(
//Create a "--test" optional parameter
new InputOption('file', 'Path of the PowerAmc MPD backup', InputOption::VALUE_REQUIRED, ''),
new InputOption('namespace', 'NameSpace for the entities (use slash "/" instead of backslash "\\")', InputOption::VALUE_REQUIRED, ''),
new InputOption('output', 'Path for the output folder', InputOption::VALUE_OPTIONAL, ''),
new InputOption('createRepository', 'Create the Repository class', InputOption::VALUE_OPTIONAL, 'FALSE'),
))
->setDescription('Generate entities from Power AMC MPD xml backup file <info>v1.0</info>')
->setHelp(<<<HELP
Usage: <info>./console.php entity:generator --file="~/model.PDM" --namespace="a/name/space" --output="~/project/"</info>
Usage: <info>./console.php entity:generator --file="~/model.PDM" --namespace="a/name/space" --output="~/project/" --createRepository=true</info>
HELP
)
->setCode(
function(InputInterface $input, OutputInterface $output) use ($app) {
$hasError = FALSE;
if (!$input->getOption('file')) {
$output->write("<error>You must set a file path</error>\n\n");
$hasError = TRUE;
} else {
if(is_file($input->getOption('file'))) {
if(!is_readable($input->getOption('file'))) {
$output->write("<error>The file is not readable</error>\n\n");
$hasError = TRUE;
}
} else {
$output->write("<error>Wrong path for the file</error>\n\n");
$hasError = TRUE;
}
}
if (!$input->getOption('namespace')) {
$output->write("<error>You must set a nemespace</error>\n\n");
$hasError = TRUE;
}
if (!$input->getOption('output')) {
$output->write("<error>You must set the path for the output folder</error>\n\n");
$hasError = TRUE;
}
if($hasError) {
exit;
}
$engine = new PowerAmcMPDParserEngine($input->getOption('file'));
$aParserResult = $engine->parseEntity();
if(isset($aParserResult["infomationMessages"]) && $aParserResult["infomationMessages"] != "") {
$output->write("<error>" . $aParserResult["infomationMessages"] . "</error>\n");
}
if(isset($aParserResult["errorMessages"]) && $aParserResult["errorMessages"] != "") {
$output->write("<error>" . $aParserResult["errorMessages"] . "</error>\n");
exit;
}
$entityGenerator = new EntityGenerator();
$entityGenerator->generateEntity(
$app,
$aParserResult["entities"],
$input->getOption('namespace'),
$input->getOption('output'),
$input->getOption('createRepository'));
$output->write("\n<info>Done</info>\n");
}
);
$console->run();