1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
/*
|
4
|
|
|
* This file is part of the "RocketORM" package.
|
5
|
|
|
*
|
6
|
|
|
* https://github.com/RocketORM/ORM
|
7
|
|
|
*
|
8
|
|
|
* For the full license information, please view the LICENSE
|
9
|
|
|
* file that was distributed with this source code.
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
namespace Rocket\ORM\Console\Command;
|
13
|
|
|
|
14
|
|
|
use Rocket\ORM\Connection\ConnectionInterface;
|
15
|
|
|
use \Rocket\ORM\Config\ConfigLoader;
|
16
|
|
|
use Rocket\ORM\Generator\Schema\Loader\SchemaLoader;
|
17
|
|
|
use Rocket\ORM\Rocket;
|
18
|
|
|
use Symfony\Component\Console\Command\Command;
|
19
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
21
|
|
|
|
22
|
|
|
/**
|
23
|
|
|
* @author Sylvain Lorinet <[email protected]>
|
24
|
|
|
*/
|
25
|
|
|
class AbstractCommand extends Command
|
26
|
|
|
{
|
27
|
|
|
/**
|
28
|
|
|
* @param InputInterface $input
|
29
|
|
|
* @param OutputInterface $output
|
30
|
|
|
*/
|
31
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output)
|
32
|
|
|
{
|
33
|
|
|
$configLoader = new ConfigLoader($input->getOption('rocket-config'));
|
34
|
|
|
Rocket::setConfiguration($configLoader->all());
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
|
/**
|
38
|
|
|
* @param InputInterface|null $input
|
39
|
|
|
* @param string|null $name
|
40
|
|
|
*
|
41
|
|
|
* @return ConnectionInterface
|
42
|
|
|
*/
|
43
|
|
|
protected function getConnection(InputInterface $input = null, $name = null)
|
44
|
|
|
{
|
45
|
|
|
if (null == $name) {
|
|
|
|
|
46
|
|
|
if (null != $input) {
|
47
|
|
|
$name = $input->getOption('connection', 'default');
|
|
|
|
|
48
|
|
|
}
|
49
|
|
|
else {
|
50
|
|
|
$name = 'default';
|
51
|
|
|
}
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
return Rocket::getConnection($name);
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
/**
|
58
|
|
|
* @param string|array $path
|
59
|
|
|
* @param string|array $exclude
|
60
|
|
|
*
|
61
|
|
|
* @return array
|
62
|
|
|
*/
|
63
|
|
|
protected function getSchemas($path, $exclude = [])
|
64
|
|
|
{
|
65
|
|
|
$schemaLoader = new SchemaLoader($path, $exclude, Rocket::getConfiguration('generator.loader'));
|
|
|
|
|
66
|
|
|
|
67
|
|
|
return $schemaLoader->load();
|
68
|
|
|
}
|
69
|
|
|
|
70
|
|
|
/**
|
71
|
|
|
* @param OutputInterface $output
|
72
|
|
|
* @param string $message
|
73
|
|
|
* @param bool $newLine
|
74
|
|
|
* @param int $verbosity
|
75
|
|
|
*/
|
76
|
|
|
private function write(OutputInterface $output, $message, $newLine = true, $verbosity = OutputInterface::VERBOSITY_VERBOSE)
|
77
|
|
|
{
|
78
|
|
|
if ($verbosity <= $output->getVerbosity()) {
|
79
|
|
|
$output->write($message);
|
80
|
|
|
if ($newLine) {
|
81
|
|
|
$output->writeln('');
|
82
|
|
|
}
|
83
|
|
|
}
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
/**
|
87
|
|
|
* @param OutputInterface $output
|
88
|
|
|
* @param string $message
|
89
|
|
|
* @param bool $newLine
|
90
|
|
|
*/
|
91
|
|
|
protected function debug(OutputInterface $output, $message, $newLine = true)
|
92
|
|
|
{
|
93
|
|
|
$this->write($output, $message, $newLine, OutputInterface::VERBOSITY_DEBUG);
|
94
|
|
|
}
|
95
|
|
|
|
96
|
|
|
/**
|
97
|
|
|
* @param OutputInterface $output
|
98
|
|
|
* @param string $message
|
99
|
|
|
* @param bool $newLine
|
100
|
|
|
*/
|
101
|
|
|
protected function verbose(OutputInterface $output, $message, $newLine = true)
|
102
|
|
|
{
|
103
|
|
|
$this->write($output, $message, $newLine, OutputInterface::VERBOSITY_VERBOSE);
|
104
|
|
|
}
|
105
|
|
|
|
106
|
|
|
/**
|
107
|
|
|
* @return string
|
108
|
|
|
*/
|
109
|
|
|
protected function getSchemaPath()
|
110
|
|
|
{
|
111
|
|
|
return __DIR__ . '/../../../../../fixtures/schemas';
|
112
|
|
|
}
|
113
|
|
|
|
114
|
|
|
/**
|
115
|
|
|
* @return string
|
116
|
|
|
*/
|
117
|
|
|
protected function getSqlOutputPath()
|
118
|
|
|
{
|
119
|
|
|
return __DIR__ . '/../../../../../fixtures/sql';
|
120
|
|
|
}
|
121
|
|
|
}
|
122
|
|
|
|